Menu

Skip to content
AppleScriptの穴
  • Home
  • Products
  • Books
  • Docs
  • Events
  • Forum
  • About This Blog
  • License
  • 仕事依頼

AppleScriptの穴

Useful & Practical AppleScript archive. Click '★Click Here to Open This Script' Link to download each AppleScript

指定ファイルをオープンするデフォルト・アプリケーションのパスを求める

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:指定ファイルをオープンするデフォルト・アプリケーションのパスを求める
— Created 2017-11-07 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set aFile to POSIX path of (choose file)
set bPath to getDefaultAppPathFromDocumentPath(aFile) of me
–>  "/Applications/Skim.app"

on getDefaultAppPathFromDocumentPath(aFile)
  set aURL to current application’s |NSURL|’s fileURLWithPath:aFile
  
set aWorkspace to current application’s NSWorkspace’s sharedWorkspace()
  
set anApp to aWorkspace’s URLForApplicationToOpenURL:aURL
  
if anApp = missing value then return false
  
return (anApp’s |path|()) as string
end getDefaultAppPathFromDocumentPath

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

指定ファイルをオープンするデフォルト・アプリケーションのBundle IDを求める

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:指定ファイルをオープンするデフォルト・アプリケーションのBundle IDを求める
— Created 2017-11-07 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set aFile to POSIX path of (choose file)
set anID to getDefaultAppIDFromDocumentPath(aFile) of me
–> "com.apple.Preview"

on getDefaultAppIDFromDocumentPath(aFile)
  set aURL to current application’s |NSURL|’s fileURLWithPath:aFile
  
set aWorkspace to current application’s NSWorkspace’s sharedWorkspace()
  
set appURL to aWorkspace’s URLForApplicationToOpenURL:aURL
  
set aBundle to current application’s NSBundle’s bundleWithURL:appURL
  
if aBundle = missing value then return false
  
set anID to aBundle’s bundleIdentifier()
  
return anID as string
end getDefaultAppIDFromDocumentPath

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

指定のアプリケーションのURL Schemeを取得する

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:指定のアプリケーションのURL Schemeを取得する
— Created 2017-07-23 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use BridgePlus : script "BridgePlus"
–http://piyocast.com/as/archives/4759

load framework

set aP to choose file
set aURLrec to getAppURLSchemes(aP) of me
–> {appName:"Photos", appBundleID:"com.apple.Photos", urlScheme:{"photos"}}

on getAppURLSchemes(aP)
  set aURL to current application’s |NSURL|’s fileURLWithPath:(POSIX path of aP)
  
set aBundle to current application’s NSBundle’s bundleWithURL:aURL
  
set aDict to aBundle’s infoDictionary()
  
  
set appNameDat to (aDict’s valueForKey:"CFBundleName") as string
  
set bundleIDat to (aDict’s valueForKey:"CFBundleIdentifier") as string
  
  
set urlSchemes to (aDict’s valueForKey:"CFBundleURLTypes")
  
if urlSchemes is not equal to missing value then
    set urlList to urlSchemes’s valueForKey:"CFBundleURLSchemes"
    
set urlListFlat to (current application’s SMSForder’s arrayByFlattening:urlList) as list
  else
    set urlListFlat to {}
  end if
  
  
set aRec to {appName:appNameDat, appBundleID:bundleIDat, urlScheme:urlListFlat}
  
return aRec
end getAppURLSchemes

★Click Here to Open This Script 

Posted in System URL | Tagged 10.11savvy 10.12savvy 10.13savvy | 1 Comment

Bundle IDで指定したアプリケーションのURL Schemeを求める

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:Bundle IDで指定したアプリケーションのURL Schemeを求める
— Created 2017-07-23 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"
use BridgePlus : script "BridgePlus" –https://www.macosxautomation.com/applescript/apps/BridgePlus.html

property |NSURL| : a reference to current application’s |NSURL|
property NSBundle : a reference to current application’s NSBundle
property SMSForder : a reference to current application’s SMSForder

load framework

set aRes to getURLSchemesFromBundleID("com.apple.Safari") of me
–>  {​​​​​appName:"Safari", ​​​​​appBundleID:"com.apple.Safari", ​​​​​urlScheme:{​​​​​​​"http", ​​​​​​​"https", ​​​​​​​"file"​​​​​}​​​}

on getURLSchemesFromBundleID(aBundleID)
  set aURL to current application’s NSWorkspace’s sharedWorkspace()’s URLForApplicationWithBundleIdentifier:aBundleID
  
if aURL = missing value then return false
  
  
set bPath to (aURL’s |path|()) as string
  
set aURLrec to getAppURLSchemes(bPath) of me
  
  
return aURLrec
end getURLSchemesFromBundleID

on getAppURLSchemes(aP)
  set aURL to |NSURL|’s fileURLWithPath:(POSIX path of aP)
  
set aBundle to NSBundle’s bundleWithURL:aURL
  
set aDict to aBundle’s infoDictionary()
  
  
set appNameDat to (aDict’s valueForKey:"CFBundleName") as string
  
set bundleIDat to (aDict’s valueForKey:"CFBundleIdentifier") as string
  
  
set urlSchemes to (aDict’s valueForKey:"CFBundleURLTypes")
  
if urlSchemes is not equal to missing value then
    set urlList to urlSchemes’s valueForKey:"CFBundleURLSchemes"
    
set urlListFlat to (SMSForder’s arrayByFlattening:urlList) as list
  else
    set urlListFlat to {}
  end if
  
  
set aRec to {appName:appNameDat, appBundleID:bundleIDat, urlScheme:urlListFlat}
  
return aRec
end getAppURLSchemes

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

指定バンドルIDのアプリケーションのアイコンへのパスを求める

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:指定バンドルIDのアプリケーションのアイコンへのパスを求める
— Created 2017-02-14 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"
–http://piyocast.com/as/archives/4460

set iconList to {"com.barebones.bbedit", "com.barebones.textwrangler", "com.apple.Finder"}
repeat with i in iconList
  set aPath to retIconPath(i) of me
  
if aPath is not equal to false then
    display dialog "ICNS test" with title i with icon ((POSIX file aPath) as alias) buttons {"OK"} default button 1
  end if
end repeat

–指定バンドルIDのアプリケーションのアイコンのフルパスを取得する
on retIconPath(anID)
  set aRes to chkAppIsInstalled(anID) of me
  
if aRes = false then return false
  
set appPathPOSIX to (current application’s NSWorkspace’s sharedWorkspace()’s absolutePathForAppBundleWithIdentifier:anID) as string
  
set anIconPath to getIconFilePath(appPathPOSIX) of me
  
return anIconPath
end retIconPath

–指定バンドルIDのアプリケーションが存在しているかチェック
on chkAppIsInstalled(aBundleID as string)
  set aRes to current application’s NSWorkspace’s sharedWorkspace()’s URLForApplicationWithBundleIdentifier:aBundleID
  
set bRes to (aRes is not equal to missing value)
  
return bRes
end chkAppIsInstalled

–指定ファイルのアイコンのファイルのパスを取得する
on getIconFilePath(aPOSIXPath)
  set anURL to current application’s |NSURL|’s fileURLWithPath:aPOSIXPath
  
set myBundle to current application’s NSBundle’s bundleWithURL:anURL
  
set aBundleID to myBundle’s bundleIdentifier() as text
  
set anIconFileName to (myBundle’s objectForInfoDictionaryKey:"CFBundleIconFile") as string
  
  
if anIconFileName does not end with ".icns" then
    set anIconFileName to anIconFileName & ".icns"
  end if
  
  
set ifonFileFullPath to aPOSIXPath & "/Contents/Resources/" & anIconFileName
  
return ifonFileFullPath
end getIconFilePath

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

Bundle IDからアプリケーション名称を取得する

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:Bundle IDからアプリケーション名称を取得する
— Created 2017-11-07 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set aBundleID to "com.apple.iWork.Keynote2"
set aRes to retNameFromBundleID(aBundleID) of me
–> "Keynote"

on retNameFromBundleID(aBundleID)
  set aURL to current application’s NSWorkspace’s sharedWorkspace()’s URLForApplicationWithBundleIdentifier:aBundleID
  
if aURL = missing value then return false –Error
  
set aBundle to current application’s NSBundle’s bundleWithURL:aURL
  
set aName to aBundle’s objectForInfoDictionaryKey:(current application’s kCFBundleExecutableKey)
  
return aName as string
end retNameFromBundleID

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

Bundle IDからアプリケーションのパスを取得する

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:Bundle IDからアプリケーションのパスを取得する
— Created 2017-11-07 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set aBundleID to "com.apple.iWork.Keynote"
set aRes to retPathFromBundleID(aBundleID) of me
–> "/Applications/iWork ’13/Keynote.app"

on retPathFromBundleID(aBundleID)
  set aURL to current application’s NSWorkspace’s sharedWorkspace()’s URLForApplicationWithBundleIdentifier:aBundleID
  
if aURL = missing value then return false –Error
  
return aURL’s |path|() as string
end retPathFromBundleID

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | 2 Comments

Bundle IDからアプリケーションのURLを取得する

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:Bundle IDからアプリケーションのURLを取得する
— Created 2017-11-07 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set aBundleID to "com.apple.iWork.Keynote"
set aRes to retURLFromBundleID(aBundleID) of me
–> "file:///Applications/iWork%20’13/Keynote.app/"

on retURLFromBundleID(aBundleID)
  set aURL to current application’s NSWorkspace’s sharedWorkspace()’s URLForApplicationWithBundleIdentifier:aBundleID
  
if aURL = missing value then return false –Error
  
return aURL’s absoluteString() as string
end retURLFromBundleID

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

指定名称のアプリケーションのBundle IDを求める

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:指定名称のアプリケーションのBundle IDを求める
— Created 2017-11-07 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set anID to getBundleIDFromAppName("Keynote") of me
–>  "com.apple.iWork.Keynote"

on getBundleIDFromAppName(appName)
  set appPath to POSIX path of (path to application appName)
  
return getBundleIDFromPath(appPath) of me
end getBundleIDFromAppName

on getBundleIDFromPath(aPOSIXpath)
  set aURL to current application’s |NSURL|’s fileURLWithPath:aPOSIXpath
  
set aWorkspace to current application’s NSWorkspace’s sharedWorkspace()
  
set appURL to aWorkspace’s URLForApplicationToOpenURL:aURL
  
set aBundle to current application’s NSBundle’s bundleWithURL:appURL
  
set anID to aBundle’s bundleIdentifier()
  
return anID as string
end getBundleIDFromPath

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

指定パスのアプリケーションのBundle IDを求める

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:指定パスのアプリケーションのBundle IDを求める
— Created 2017-11-07 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set aFile to POSIX path of (choose file)
set anID to getBundleIDFromPath(aFile) of me
–>  "com.apple.ScriptEditor2"

on getBundleIDFromPath(aPOSIXpath)
  set aURL to current application’s |NSURL|’s fileURLWithPath:aPOSIXpath
  
set aWorkspace to current application’s NSWorkspace’s sharedWorkspace()
  
set appURL to aWorkspace’s URLForApplicationToOpenURL:aURL
  
set aBundle to current application’s NSBundle’s bundleWithURL:appURL
  
set anID to aBundle’s bundleIdentifier()
  
return anID as string
end getBundleIDFromPath

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

Bundle IDで指定したアプリケーションのローカライズ一覧を取得

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:Bundle IDで指定したアプリケーションのローカライズ一覧を取得
— Created 2017-11-07 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aRes to getLocalizationsFromBundleID("com.apple.Safari") of me
–>  {​​​​​"ar", ​​​​​"Base", ​​​​​"ca", ​​​​​"cs", ​​​​​"da", ​​​​​"de", ​​​​​"el", ​​​​​"en", ​​​​​"es", ​​​​​"es_419", ​​​​​"fi", ​​​​​"fr", ​​​​​"he", ​​​​​"hr", ​​​​​"hu", ​​​​​"id", ​​​​​"it", ​​​​​"ja", ​​​​​"ko", ​​​​​"ms", ​​​​​"nl", ​​​​​"no", ​​​​​"pl", ​​​​​"pt", ​​​​​"pt_PT", ​​​​​"ro", ​​​​​"ru", ​​​​​"sk", ​​​​​"sv", ​​​​​"th", ​​​​​"tr", ​​​​​"uk", ​​​​​"vi", ​​​​​"zh_CN", ​​​​​"zh_TW"​​​}

set bRes to getLocalizationsFromBundleID("com.apple.iWork.Pages") of me
–>  {​​​​​"ar", ​​​​​"Base", ​​​​​"ca", ​​​​​"cs", ​​​​​"da", ​​​​​"de", ​​​​​"el", ​​​​​"en", ​​​​​"es", ​​​​​"fi", ​​​​​"fr", ​​​​​"he", ​​​​​"hr", ​​​​​"hu", ​​​​​"id", ​​​​​"it", ​​​​​"ja", ​​​​​"ko", ​​​​​"ms", ​​​​​"nl", ​​​​​"no", ​​​​​"pl", ​​​​​"pt", ​​​​​"pt_PT", ​​​​​"ro", ​​​​​"ru", ​​​​​"sk", ​​​​​"sv", ​​​​​"th", ​​​​​"tr", ​​​​​"uk", ​​​​​"vi", ​​​​​"zh_CN", ​​​​​"zh_TW"​​​}

set cRes to getLocalizationsFromBundleID("com.adobe.Photoshop") of me
–>  {​​​​​"cs", ​​​​​"da", ​​​​​"de", ​​​​​"en-GB", ​​​​​"en", ​​​​​"English", ​​​​​"es", ​​​​​"fi", ​​​​​"fr-CA", ​​​​​"fr", ​​​​​"hu", ​​​​​"it", ​​​​​"ja", ​​​​​"ko", ​​​​​"nb", ​​​​​"nl", ​​​​​"no", ​​​​​"pl", ​​​​​"pt", ​​​​​"ru", ​​​​​"sk", ​​​​​"sv", ​​​​​"tr", ​​​​​"uk", ​​​​​"zh-Hans", ​​​​​"zh-Hant"​​​}

set dRes to getLocalizationsFromBundleID("com.adobe.InDesign") of me
–>  {​​​​​"cs", ​​​​​"da", ​​​​​"de", ​​​​​"el", ​​​​​"en", ​​​​​"en_GB", ​​​​​"English", ​​​​​"es", ​​​​​"fi", ​​​​​"fr", ​​​​​"hu", ​​​​​"it", ​​​​​"ja", ​​​​​"ko", ​​​​​"nb", ​​​​​"nl", ​​​​​"pl", ​​​​​"pt", ​​​​​"ro", ​​​​​"ru", ​​​​​"sq", ​​​​​"sv", ​​​​​"tr", ​​​​​"uk", ​​​​​"zh_CN", ​​​​​"zh_TW"​​​}

set eRes to getLocalizationsFromBundleID("com.adobe.Illustrator") of me
–>  {​​​​​"cs", ​​​​​"da", ​​​​​"de", ​​​​​"el", ​​​​​"en", ​​​​​"es", ​​​​​"fi", ​​​​​"fr", ​​​​​"hu", ​​​​​"it", ​​​​​"ja", ​​​​​"ko", ​​​​​"nl", ​​​​​"no", ​​​​​"pl", ​​​​​"pt", ​​​​​"ro", ​​​​​"ru", ​​​​​"sv", ​​​​​"tr", ​​​​​"uk", ​​​​​"zh_CN", ​​​​​"zh_TW"​​​}

on getLocalizationsFromBundleID(aBundleID)
  set aRes to retPathFromBundleID(aBundleID) of me
  
if aRes = false then error "Wrong Bundle ID."
  
return getSpecifiedAppFilesLocalizationListWithDuplication(aRes) of me
end getLocalizationsFromBundleID

–指定アプリケーションファイルの、指定Localeにおけるローカライズ言語リストを求める。重複を許容
on getSpecifiedAppFilesLocalizationListWithDuplication(appPOSIXpath)
  set aURL to (current application’s |NSURL|’s fileURLWithPath:appPOSIXpath)
  
set aBundle to current application’s NSBundle’s bundleWithURL:aURL
  
set locList to aBundle’s localizations()
  
return locList as list
end getSpecifiedAppFilesLocalizationListWithDuplication

on retPathFromBundleID(aBundleID)
  set aURL to current application’s NSWorkspace’s sharedWorkspace()’s URLForApplicationWithBundleIdentifier:aBundleID
  
if aURL = missing value then return false –Error
  
return aURL’s |path|() as string
end retPathFromBundleID

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

アプリケーションバンドル内のファイルパスを取得する

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:アプリケーションバンドル内のファイルパスを取得する
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

property |NSURL| : a reference to current application’s |NSURL|
property NSFileManager : a reference to current application’s NSFileManager

set aRes to getPathsIn_maxfiles_("/Applications/Safari.app", 4096)
–> {"/Applications/Safari.app/Contents", "/Applications/Safari.app/Contents/_CodeSignature", "/Applications/Safari.app/Contents/_CodeSignature/CodeResources", ….

— Example of file manager directory enumeration
on getPathsIn:folderPath maxfiles:MaxNum
  
  
script spd
    property aList : {}
  end script
  
  
set aList of spd to {}
  
  
set theNSURL to |NSURL|’s fileURLWithPath:folderPath
  
set theNSFileManager to NSFileManager’s new()
  
  
— get URL enumerator
  
set theNSFileEnumerator to theNSFileManager’s enumeratorAtURL:theNSURL includingPropertiesForKeys:{} options:0 errorHandler:(missing value)
  
  
repeat with i from 1 to MaxNum — arbitrary number
    — get next URL in enumerator
    
set anNSURL to theNSFileEnumerator’s nextObject()
    
if anNSURL is missing value then exit repeat — missing value means there are no more
    
    
set the end of (aList of spd) to (anNSURL’s |path|() as text)
  end repeat
  
  
return (aList of spd)
  
end getPathsIn:maxfiles:

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

指定のアプリケーションのInfo.plistの任意の属性値を取得する

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:指定のアプリケーションのInfo.plistの任意の属性値を取得する
— Created 2017-07-23 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use BridgePlus : script "BridgePlus"
–http://piyocast.com/as/archives/4759

load framework

set aP to choose file
set aURLrec to getAppPropertyFromInfoPlist(aP, "NSAppleScriptEnabled") of me
–> {appName:"Photos", appBundleID:"com.apple.Photos", urlScheme:{"photos"}}

on getAppPropertyFromInfoPlist(aP, aPropertyLabel)
  set aURL to current application’s |NSURL|’s fileURLWithPath:(POSIX path of aP)
  
set aBundle to current application’s NSBundle’s bundleWithURL:aURL
  
set aDict to aBundle’s infoDictionary()
  
  
set appNameDat to (aDict’s valueForKey:"CFBundleName") as string
  
set bundleIDat to (aDict’s valueForKey:"CFBundleIdentifier") as string
  
  
set aRes to aDict’s valueForKey:aPropertyLabel
  
if aRes is not equal to missing value then
    set aRes to aRes as string
  end if
  
set aRec to {appName:appNameDat, appBundleID:bundleIDat, propRes:aRes}
  
return aRec
end getAppPropertyFromInfoPlist

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

指定のアプリケーションのInfo.plistのすべての属性値を取得する

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:指定のアプリケーションのInfo.plistのすべての属性値を取得する
— Created 2017-07-23 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aP to choose file
set aURLrec to getAppAllPropertyFromInfoPlist(aP) of me
–>  (NSDictionary) {​​​​​DTCompiler:"com.apple.compilers.llvm.clang.1_0", ​​​​​NSAppleScriptEnabled:"YES", ​​​​​CFBundleInfoDictionaryVersion:"6.0", ​​​​​DTPlatformVersion:"GM", ​​​​​CFBundleIconFile:"Automator.icns", ​​​​​CFBundleName:"Automator", ​​​​​DTSDKName:"macosx10.12internal", ​​​​​NSServices:{​​​​​​​{​​​​​​​​​NSMenuItem:{​​​​​​​​​​​default:"Create Service"​​​​​​​​​}, ​​​​​​​​​NSSendTypes:{​​​​​​​​​​​"NSStringPboardType", ​​​​​​​​​​​"NSFilenamesPboardType"​​​​​​​​​}, ​​​​​​​​​…

on getAppAllPropertyFromInfoPlist(aP)
  set aURL to current application’s |NSURL|’s fileURLWithPath:(POSIX path of aP)
  
set aBundle to current application’s NSBundle’s bundleWithURL:aURL
  
set aDict to aBundle’s infoDictionary()
  
return aDict
end getAppAllPropertyFromInfoPlist

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

値を指定してCIColorを作成

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:値を指定してCIColorを作成
— Created 2017-04-19 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "QuartzCore"

set redValue to 0
set greenValue to 0
set blueValue to 1
set alphaVlaue to 1.0

set aCIColor to current application’s CIColor’s alloc()’s initWithRed:redValue green:greenValue blue:blueValue alpha:alphaVlaue
–>  (CIColor) (0 0 1 1)

★Click Here to Open This Script 

Posted in Color | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

NSColorからCIColorを作成

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:NSColorからCIColorを作成
— Created 2017-04-19 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "QuartzCore"
use framework "AppKit"

set redValue to 0
set greenValue to 0
set blueValue to 1
set alphaVlaue to 1.0

set aNSColor to current application’s NSColor’s colorWithCalibratedRed:redValue green:greenValue blue:blueValue alpha:alphaVlaue
set aCIColor to current application’s CIColor’s alloc()’s initWithColor:aNSColor
–>  (CIColor) (0 0 1 1)

★Click Here to Open This Script 

Posted in Color | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

GPUImageで指定画像が真っ白かどうか判定する

Posted on 2月 6, 2018 by Takaaki Naganoya

GPUImage Frameworkを用いて、指定画像が真っ白かどうかを判定するAppleScriptです。

–> GPUImage.framework(To ~/Library/Frameworks/)

指定画像のドットがすべて白いかどうかを判定する処理を真剣に行うと、かなり大変です。

いまでは大したことのない1,024 x 768のサイズの画像であっても、ピクセル数は786,432個。78万ピクセルのデータをRGBの各チャネルについてチェックを行う必要があります。78万×3=240万要素ぐらいの処理を行うわけで、メモリ8Gバイト搭載のMacでAppleScriptを用いて処理するのはつらいものがあります(AppleScriptの配列であるlist型変数はメモリ効率がそれほどよくないので)。

240万要素のList型変数(配列)をループで全要素チェックするだけでもけっこうな時間がかかります。こうした地道なアプローチで攻めるのは物理的に不可能です。実用的ではありません。

すべてのピクセルが白いかチェックするのに実用的な処理といえば、Adobe Photoshopで画像の明度ヒストグラムを求めて、ヒストグラムの配列をチェックするというものがあります(実戦に投入していました)。ただし、処理を行うのにAdobe Photoshopが必要になります。Photoshopがない環境では手も足も出ません。

そこで、GPUImage.frameworkをAppleScriptから呼び出してヒストグラムを計算する方法を見つけました。これであれば、AppleScriptと一緒に配布することも可能ですし、処理もPhotoshopより(起動時間を勘案すると)高速に行えます。

実際に、1024×768および1980×1200の真っ白い画像を作成し、それぞれ1ピクセルだけ黒く塗りつぶして空白検出を行なったところ「空白ではない」ことを検知できました(ただし、1×1の画像の判定をミスするという問題がありました)。

GPUImageのヒストグラム出力は、結果にArrayが返ってくるわけでもなく、ヒストグラム出力「画像」が出てくるだけです。その画像を256ピクセルほどスキャンして検出しています。

指定画像がすべて白いかチェックを行う演算は、PDFの空白ページの検出で利用しています。テキストだけではなく、グラフィック要素が指定ページに存在しているかどうかをチェックするために、GPUImage.frameworkのこのヒストグラム出力機能を利用しています。

GPUImage.framework自体は、Swiftで書き直されたGPUImage2に移行。さらにAppleから OpenGLとOpenGL ESが非推奨になりMetalが推奨になったためにGPUImage2も今度の動向がどうなるか不明。新たなGPUImage3に移行するのか、GPUImage2の機能のまましばらく行くのか動向が気になります(結局、Metal対応のGPUImage3に移行)。

各種の画像フィルター処理については代替手段があるものの、このヒストグラム計算による空白画像検出については現時点で代替手段がないため、調査しておきたいところです。ヒストグラム計算自体はありふれた演算なのですが、Objective-Cでラッピングされている例が少ないので、自分でプログラムを書かないといけないのかもしれません。

→ AppleScriptだけで本Scriptよりも高速に画像の空白判定を行えるようになりました(画像の空白判定 v4)。GPUImage.frameworkの機能はこの種類の処理にはもう使っていません。

AppleScript名:GPUImageで指定画像が真っ白かどうか判定する
— Created 2017-02-12 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"
use framework "GPUImage"
use framework "Quartz"
use framework "QuartzCore"
use framework "CoreGraphics"

set aFile to POSIX path of (choose file of type {"public.image"} with prompt "Select a image to check which is blank (or not) ")

set aURL to current application’s |NSURL|’s fileURLWithPath:aFile
set anNSImage to current application’s NSImage’s alloc()’s initWithContentsOfURL:aURL

set wRes to my detectAllWhite:anNSImage
–> true (Blank = White)
–> false (Not Blank = Not White)

–指定のNSImageが真っ白かどうかをチェック
on detectAllWhite:anNSImage
  –グレースケールフィルタを通して色要素を削除
  
set grayImage to filterWithNSImage(anNSImage, "GPUImageGrayscaleFilter") of me
  
  
–明度ヒストグラム画像を取得
  
set imgRes to getHistogramFromImage(grayImage, 4) of me
  
  
–画像のサイズ(幅、高さ)をピクセル数で取得する(念のため)
  
set aSize to imgRes’s |size|()
  
set aWidth to aSize’s width()
  
set aHeight to aSize’s height()
  
  
set aRawimg to current application’s NSBitmapImageRep’s imageRepWithData:(imgRes’s TIFFRepresentation())
  
  
–白い画像のデータパターン
  
set aWhitePattern to current application’s NSMutableArray’s arrayWithArray:{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0}
  
  
set resArray to current application’s NSMutableArray’s alloc()’s init()
  
repeat with i from 0 to 255
    set origColor to (aRawimg’s colorAtX:i y:1)
    
set srgbColSpace to current application’s NSColorSpace’s genericGrayColorSpace
    
set aColor to (origColor’s colorUsingColorSpace:srgbColSpace)
    
set aWhite to aColor’s whiteComponent()
    (
resArray’s addObject:aWhite)
  end repeat
  
  
set aRes to (resArray’s isEqualTo:aWhitePattern) as boolean
  
return aRes
  
end detectAllWhite:

–各種ヒストグラムの定数(From GPUImage.framework)
–0:kGPUImageHistogramRed
–1:kGPUImageHistogramGreen
–2:kGPUImageHistogramBlue
–3:kGPUImageHistogramRGB
–4:kGPUImageHistogramLuminance

–指定のNSImageを明度ヒストグラム化してNSImageで返す
on getHistogramFromImage(aNSImage, histogramType)
  set aFilter to current application’s GPUImageHistogramFilter’s alloc()’s initWithHistogramType:histogramType
  
set aProcImg to (aFilter’s imageByFilteringImage:aNSImage)
  
return aProcImg
end getHistogramFromImage

–NSImageをGPUImage.frameworkの指定フィルタで処理してNSImageを返す
on filterWithNSImage(aNSImage, filterName as string)
  set aClass to current application’s NSClassFromString(filterName)
  
set aImageFilter to aClass’s alloc()’s init()
  
set aProcImg to (aImageFilter’s imageByFilteringImage:aNSImage)
  
return aProcImg
end filterWithNSImage

★Click Here to Open This Script 

Posted in Image | Tagged 10.11savvy 10.12savvy 10.13savvy | 2 Comments

任意の2色の色差ΔEを求める

Posted on 2月 6, 2018 by Takaaki Naganoya

Coloursをフレームワーク化したcolorsKit.frameworkを呼び出して、指定の任意のRGB色2色の色差(ΔE)を計算するAppleScriptです。

色差を求めるためには、RGB色をXYZを経由してL*a*b*色に変換する必要があります。変換自体はColoursの内蔵機能で行っています。

ただし、色差を求める際にNSColor’s whiteColor()などと通常のメソッドで求めたNSColorとColoursの機能を用いて求めたNSColorとの間で計算をするとエラーになります。色差の計算はColoursの機能を用いて作成したNSColor同士で行う必要があるようです。

–> colorsKit.framework

AppleScript名:任意の2色の色差ΔEを求める
— Created 2017-12-29 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "colorsKit" –https://github.com/bennyguitar/Colours
use framework "AppKit"

property NSColor : a reference to current application’s NSColor

set aASCol to choose color
set bASCol to choose color

set aCocoaList to retCocoaColorList(aASCol, 65535) of me
set bCocoaList to retCocoaColorList(bASCol, 65535) of me

set aCol to NSColor’s colorFromRGBAArray:aCocoaList
set bCol to NSColor’s colorFromRGBAArray:bCocoaList

set aDist to aCol’s distanceFromColor:bCol type:2 –ColorDistanceCIE2000

return aDist

–Convert "choose color" RGB list (0-65535) to Cocoa color RGBA Array (0.0-1.0)
on retCocoaColorList(aColorList, aMax)
  set cocoaColorList to {}
  
repeat with i in aColorList
    set the end of cocoaColorList to i / aMax
  end repeat
  
set the end of cocoaColorList to 1.0
  
return cocoaColorList
end retCocoaColorList

★Click Here to Open This Script 

Posted in Color | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

文字列のURLエンコード、URLデコード

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:文字列のURLエンコード、URLデコード
— Created 2017-09-19 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aStr to "あいうえお"

set bStr to encodeURLencoding(aStr) of me
–>  "%E3%81%82%E3%81%84%E3%81%86%E3%81%88%E3%81%8A"

set cStr to decodeURLencoding(bStr) of me
–>  "あいうえお"

on encodeURLencoding(origStr as string)
  set aStr to current application’s NSString’s stringWithString:origStr
  
set encodedStr to aStr’s stringByAddingPercentEscapesUsingEncoding:(current application’s NSUTF8StringEncoding)
  
return encodedStr as string
end encodeURLencoding

on decodeURLencoding(encodedStr)
  set aStr to current application’s NSString’s stringWithString:encodedStr
  
set bStr to aStr’s stringByReplacingPercentEscapesUsingEncoding:(current application’s NSUTF8StringEncoding)
  
return bStr as string
end decodeURLencoding

★Click Here to Open This Script 

Posted in URL | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

URLにリソースが存在するかチェック v4

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:URLにリソースが存在するかチェック v4
— Created 2016-10-18 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

set aStr to "http://piyocast.com/as/wp-content/uploads/2018/02/map2-1024×796.png"

set aURL to (current application’s |NSURL|’s URLWithString:aStr)
set {exRes, headerRes, aData} to checkURLResourceExistence(aURL, 3) of me

log exRes
–> true / false

return {exRes, headerRes as record}
–> {true, {|content-type|:"image/png", |keep-alive|:"timeout=1, max=100", Server:"Apache", Expires:"Tue, 06 Feb 2018 09:52:20 GMT", |cache-control|:"max-age=300", |date|:"Tue, 06 Feb 2018 09:47:30 GMT", |content-length|:"323366", Connection:"Keep-Alive", |x-content-type-options|:"nosniff", Etag:"\"1f81fd7-4ef26-564871949b4c7\"", |accept-ranges|:"bytes", |last-modified|:"Tue, 06 Feb 2018 08:38:11 GMT"}}

— 指定URLにファイル(画像など)が存在するかチェック
–> {存在確認結果(boolean), レスポンスヘッダー(NSDictionary), データ(NSData)}
on checkURLResourceExistence(aURL, timeOutSec as real)
  set aRequest to (current application’s NSURLRequest’s requestWithURL:aURL cachePolicy:(current application’s NSURLRequestUseProtocolCachePolicy) timeoutInterval:timeOutSec)
  
set aRes to (current application’s NSURLConnection’s sendSynchronousRequest:aRequest returningResponse:(reference) |error|:(missing value))
  
set dRes to (first item of (aRes as list))
  
set bRes to (second item of (aRes as list))
  
if bRes is not equal to missing value then
    set hRes to (bRes’s allHeaderFields())
    
set aResCode to (bRes’s statusCode()) as integer
  else
    set hRes to {}
    
set aResCode to -1 –error
  end if
  
return {(aResCode = 200), hRes, dRes}
end checkURLResourceExistence

★Click Here to Open This Script 

Posted in 未分類 | Tagged 10.11savvy 10.12savvy 10.13savvy | 1 Comment

Post navigation

  • Older posts
  • Newer posts

電子書籍(PDF)をオンラインストアで販売中!

Google Search

Popular posts

  • Numbersで選択範囲のセルの前後の空白を削除
  • macOS 26, Tahoe
  • macOS 15でも変化したText to Speech環境
  • KagiのWebブラウザ、Orion
  • Script Debuggerの開発と販売が2025年に終了
  • 【続報】macOS 15.5で特定ファイル名パターンのfileをaliasにcastすると100%クラッシュするバグ
  • macOS 15 リモートApple Eventsにバグ?
  • NSObjectのクラス名を取得 v2.1
  • 2024年に書いた価値あるAppleScript
  • macOS 15:スクリプトエディタのAppleScript用語辞書を確認できない
  • (確認中)AppleScript Dropletのバグっぽい動作が解消?
  • Xcode上のAppleScriptObjCのプログラムから、Xcodeのログ欄へのメッセージ出力を実行
  • AVSpeechSynthesizerで読み上げテスト
  • AppleScript Dropletのバグっぽい動作が「復活」(macOS 15.5β)
  • Apple、macOS標準搭載アプリ「写真」のバージョン表記を間違える
  • 指定フォルダ以下の画像のMD5チェックサムを求めて、重複しているものをピックアップ
  • macOS 26, 15.5でShortcuts.app「AppleScriptを実行」アクションのバグが修正される
  • Script Debuggerがフリーダウンロードで提供されることに
  • Numbersで選択中の2列のセルを比較して並べ直して書き戻す v2
  • macOS 15.5beta5(24F74)でaliasのキャスティングバグが修正された???

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1391) 10.14savvy (587) 10.15savvy (438) 11.0savvy (283) 12.0savvy (212) 13.0savvy (204) 14.0savvy (159) 15.0savvy (157) CotEditor (66) Finder (52) Keynote (119) NSAlert (61) NSArray (51) NSBitmapImageRep (20) NSBundle (20) NSButton (34) NSColor (53) NSDictionary (28) NSFileManager (23) NSFont (21) NSImage (41) NSJSONSerialization (21) NSMutableArray (63) NSMutableDictionary (22) NSPredicate (36) NSRunningApplication (56) NSScreen (30) NSScrollView (22) NSString (119) NSURL (98) NSURLRequest (23) NSUTF8StringEncoding (30) NSView (33) NSWorkspace (20) Numbers (76) Pages (56) Pixelmator Pro (20) Safari (44) Script Editor (27) WKUserContentController (21) WKUserScript (20) WKWebView (23) WKWebViewConfiguration (22)

カテゴリー

  • 2D Bin Packing
  • 3D
  • AirDrop
  • AirPlay
  • Animation
  • AppleScript Application on Xcode
  • Beginner
  • Benchmark
  • beta
  • Bluetooth
  • Books
  • boolean
  • bounds
  • Bug
  • Calendar
  • call by reference
  • check sum
  • Clipboard
  • Cocoa-AppleScript Applet
  • Code Sign
  • Color
  • Custom Class
  • date
  • dialog
  • diff
  • drive
  • Droplet
  • exif
  • file
  • File path
  • filter
  • folder
  • Font
  • Font
  • GAME
  • geolocation
  • GUI
  • GUI Scripting
  • Hex
  • History
  • How To
  • iCloud
  • Icon
  • Image
  • Input Method
  • Internet
  • iOS App
  • JavaScript
  • JSON
  • JXA
  • Keychain
  • Keychain
  • Language
  • Library
  • list
  • Locale
  • Localize
  • Machine Learning
  • Map
  • Markdown
  • Menu
  • Metadata
  • MIDI
  • MIME
  • Natural Language Processing
  • Network
  • news
  • Newt On Project
  • Noification
  • Notarization
  • Number
  • Object control
  • OCR
  • OSA
  • parallel processing
  • PDF
  • Peripheral
  • process
  • PRODUCTS
  • QR Code
  • Raw AppleEvent Code
  • Record
  • rectangle
  • recursive call
  • regexp
  • Release
  • Remote Control
  • Require Control-Command-R to run
  • REST API
  • Review
  • RTF
  • Sandbox
  • Screen Saver
  • Script Libraries
  • Scripting Additions
  • sdef
  • search
  • Security
  • selection
  • shell script
  • Shortcuts Workflow
  • Sort
  • Sound
  • Spellchecker
  • Spotlight
  • SVG
  • System
  • Tag
  • Telephony
  • Text
  • Text to Speech
  • timezone
  • Tools
  • Update
  • URL
  • UTI
  • Web Contents Control
  • WiFi
  • XML
  • XML-RPC
  • イベント(Event)
  • 未分類

アーカイブ

  • 2025年11月
  • 2025年10月
  • 2025年9月
  • 2025年8月
  • 2025年7月
  • 2025年6月
  • 2025年5月
  • 2025年4月
  • 2025年3月
  • 2025年2月
  • 2025年1月
  • 2024年12月
  • 2024年11月
  • 2024年10月
  • 2024年9月
  • 2024年8月
  • 2024年7月
  • 2024年6月
  • 2024年5月
  • 2024年4月
  • 2024年3月
  • 2024年2月
  • 2024年1月
  • 2023年12月
  • 2023年11月
  • 2023年10月
  • 2023年9月
  • 2023年8月
  • 2023年7月
  • 2023年6月
  • 2023年5月
  • 2023年4月
  • 2023年3月
  • 2023年2月
  • 2023年1月
  • 2022年12月
  • 2022年11月
  • 2022年10月
  • 2022年9月
  • 2022年8月
  • 2022年7月
  • 2022年6月
  • 2022年5月
  • 2022年4月
  • 2022年3月
  • 2022年2月
  • 2022年1月
  • 2021年12月
  • 2021年11月
  • 2021年10月
  • 2021年9月
  • 2021年8月
  • 2021年7月
  • 2021年6月
  • 2021年5月
  • 2021年4月
  • 2021年3月
  • 2021年2月
  • 2021年1月
  • 2020年12月
  • 2020年11月
  • 2020年10月
  • 2020年9月
  • 2020年8月
  • 2020年7月
  • 2020年6月
  • 2020年5月
  • 2020年4月
  • 2020年3月
  • 2020年2月
  • 2020年1月
  • 2019年12月
  • 2019年11月
  • 2019年10月
  • 2019年9月
  • 2019年8月
  • 2019年7月
  • 2019年6月
  • 2019年5月
  • 2019年4月
  • 2019年3月
  • 2019年2月
  • 2019年1月
  • 2018年12月
  • 2018年11月
  • 2018年10月
  • 2018年9月
  • 2018年8月
  • 2018年7月
  • 2018年6月
  • 2018年5月
  • 2018年4月
  • 2018年3月
  • 2018年2月

https://piyomarusoft.booth.pm/items/301502

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org

Forum Posts

  • 人気のトピック
  • 返信がないトピック

メタ情報

  • ログイン
  • 投稿フィード
  • コメントフィード
  • WordPress.org
Proudly powered by WordPress
Theme: Flint by Star Verte LLC