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

タグ: 10.12savvy

InputMethodで現在選択中のIM名を文字列で取得する

Posted on 2月 6, 2018 by Takaaki Naganoya

–> InputManager.framework

AppleScript名:InputMethodで現在選択中のIM名を文字列で取得する
— Created 2017-01-22 22:11:33 +0900 by Takaaki Naganoya
— 2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "InputManager"

set c2 to (current application’s CSInputSource’s mInputSource()) –>  "英字"
–>  "ひらがな"
–>  "カタカナ"

★Click Here to Open This Script 

Posted in Input Method System | Tagged 10.11savvy 10.12savvy 10.13savvy | Leave a comment

全国地方公共団体コードのチェックサム算出 v2

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:全国地方公共団体コードのチェックサム算出 v2
set chkSum to chkModulas11("01100") of me

–全国地方公共団体コードのチェックサム算出
on chkModulas11(aCodeNumStr)
  
  
if length of (aCodeNumStr as string) is not equal to 5 then return false
  
set cList to characters of (aCodeNumStr as string)
  
set aMultNum to 6
  
set aRes to 0
  
  
–第1桁から第5桁までの数字に、それぞれ6.5.4.3.2を乗じて算出した積の和を求め
  
repeat with i in cList
    set j to i as number
    
set aRes to aRes + j * aMultNum
    
set aMultNum to aMultNum – 1
  end repeat
  
  
if aRes < 11 then
    –ただし、積の和が11より小なるときは、検査数字は、11から積の和を控除した数字とする
    
set eRes to 11 – aRes
  else
    –通常パターン
    
–その和を11で除し、商と剰余(以下「余り数字」という。)を求めて
    
set cRes to aRes mod 11 –余りだけでよいのでは? 商を求めなくても余りは計算可能
    
set dRes to 11 – cRes
    
set eRes to last character of (dRes as string) –下1桁の数字を検査数字とする    
  end if
  
  
return eRes as number
end chkModulas11

★Click Here to Open This Script 

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

JANコードのチェックデジットの計算

Posted on 2月 6, 2018 by Takaaki Naganoya
AppleScript名:JANコードのチェックデジットの計算
set aData to "240469540245" –女性用カジュアルパンプス(黒)
set aSum to calcJANcodeChkSum(aData)
–> 9

set aData to "978479731648" –「Mac使いへの道」
set aSum to calcJANcodeChkSum(aData)
–> 3

–JANコードのチェックデジットの計算
–参照元:http://www.kabukoba.co.jp/info/barcode/check.htm
on calcJANcodeChkSum(aData)
  set aList to characters of aData
  
  
if length of aList is not equal to 12 then return false
  
  
set kiSnum to 0
  
set guNum to 0
  
  
repeat with i from 2 to length of aList
    
    
set kiSuF to ((i – 1) mod 2)
    
    
set j to (item i of aList) as number
    
    
if kiSuF = 1 then
      –奇数
      
set kiSnum to kiSnum + j
    else
      –偶数
      
set guNum to guNum + j
    end if
    
  end repeat
  
  
set kiSnum to kiSnum * 3
  
set guNum to guNum + (first item of aList) as number
  
  
set totalNum to kiSnum + guNum
  
  
set totalChar to totalNum as string
  
set lastDig to (last character of totalChar) as number
  
if lastDig is not equal to 0 then
    set sumNum to 10 – lastDig
  else
    set sumNum to 0
  end if
  
  
return sumNum
  
end calcJANcodeChkSum

★Click Here to Open This Script 

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

keychainLib

Posted on 2月 6, 2018 by Takaaki Naganoya

オープンソースのSAMKeychainを用いてキーチェーンにアクセスし、指定項目のパスワードの取得、新規項目の作成、キーチェーン項目の検索、アカウントの取得、項目の削除などを行うAppleScriptです。

# Apitoreは2019年5月31日をもってサービスを終了

オープンソースのSAMKeychainをCocoa Framework化したkeychainLib.frameworkをインストールを呼び出しています。

–> SSKeychain.framework

かつて、Mac OS X上にはKeychain ScriptingというAppleScriptから呼び出す専用の補助プログラムがOSに標準装備されていましたが、OS X 10.7で廃止になりました。以後、OS X 10.9までshell commandのsecurityコマンドを呼び出すことが必要となっていましたが、OS X 10.10でAppleScriptがCocoa呼び出しに対応したため、このような使い方ができるようになった次第です。

AppleScript名:keychainLib
— Created 2016-12-02 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "SSKeychain" –https://github.com/soffes/sskeychain

property kSSKeychainServiceName : "SSToolkitTestService"
property kSSKeychainAccountName : "SSToolkitTestAccount"
property kSSKeychainPassword : "SSToolkitTestPassword"
property kSSKeychainLabel : "SSToolkitLabel"

set kRes to getPasswordForAccount("apitore API Key", "maro@piyocast.com") of me
–> "xxXXXxxX-XxXx-XXXX-xXXX-XXxXXxxXxxXx"

–Get Password
on getPasswordForAccount(aServiceName as string, anAccount as string)
  set bQuery to current application’s SSKeychainQuery’s alloc()’s init()
  
bQuery’s setService:aServiceName
  
bQuery’s setAccount:anAccount
  
bQuery’s setPassword:(missing value)
  
set bRes to (bQuery’s fetch:(missing value)) as boolean
  
return (bQuery’s |password|()) as string
end getPasswordForAccount

— New item
on makeNewItem(aPassword as string, aServiceName as string, anAccount as string, aLabel as string)
  set aQuery to current application’s SSKeychainQuery’s alloc()’s init()
  
aQuery’s setPassword:aPassword
  
aQuery’s setService:aServiceName
  
aQuery’s setAccount:anAccount
  
aQuery’s setLabel:aLabel
  
return (aQuery’s |save|:(missing value)) as boolean
end makeNewItem

— Look up
on lookUpPassWord(aServiceName, anAccount)
  set bQuery to current application’s SSKeychainQuery’s alloc()’s init()
  
bQuery’s setService:aServiceName
  
bQuery’s setAccount:anAccount
  
bQuery’s setPassword:(missing value)
  
set bRes to (bQuery’s fetch:(missing value)) as boolean
  
return (bQuery’s |password|() ≠ missing value)
end lookUpPassWord

— Search for all accounts
on getAllAccounts()
  set cQuery to current application’s SSKeychainQuery’s alloc()’s init()
  
return (cQuery’s fetchAll:(missing value)) as list
  
–>  (NSArray) {​​​​​{​​​​​​​mdat:(NSDate) 2010-02-23 08:36:19 +0000, ​​​​​​​cdat:(NSDate) 2010-02-23 08:36:19 +0000, ​​​​​​​acct:"GoogleJapaneseInput", ​​​​​​​class:"genp", ​​​​​​​svce:"GoogleJapaneseInput", ​​​​​​​labl:"GoogleJapaneseInput", ​​​​​​​crtr:9999999999​​​​​}, ​​​​​……
end getAllAccounts

— Check accounts for service
on getAccount(aServiceName)
  set cQuery to current application’s SSKeychainQuery’s alloc()’s init()
  
cQuery’s setService:aServiceName
  
return (cQuery’s fetchAll:(missing value)) as list
  
–>  (NSArray) {​​​​​{​​​​​​​mdat:(NSDate) 2016-03-02 13:54:54 +0000, ​​​​​​​cdat:(NSDate) 2016-03-02 13:44:19 +0000, ​​​​​​​svce:"SSToolkitTestService", ​​​​​​​acct:"SSToolkitTestAccount", ​​​​​​​class:"genp", ​​​​​​​labl:"SSToolkitLabel"​​​​​}​​​}
end getAccount

— Delete
on deleteKeychain(aServiceName, anAccountName)
  set dQuery to current application’s SSKeychainQuery’s alloc()’s init()
  
dQuery’s setService:aServiceName
  
dQuery’s setAccount:anAccountName
  
return (dQuery’s deleteItem:(missing value)) as boolean
end deleteKeychain

–Test Password Object
on testPasswordObject()
  set eQuery to current application’s SSKeychainQuery’s alloc()’s init()
  
eQuery’s setService:kSSKeychainServiceName
  
eQuery’s setAccount:kSSKeychainAccountName
  
set eDic1 to current application’s NSDictionary’s dictionaryWithObjectsAndKeys_(42, "number", "Hello World", "string", missing value)
  
eQuery’s setPasswordObject:eDic1
  
set fRes to (eQuery’s |save|:(missing value)) as boolean
  
  
set fQuery to current application’s SSKeychainQuery’s alloc()’s init()
  
fQuery’s setService:kSSKeychainServiceName
  
fQuery’s setAccount:kSSKeychainAccountName
  
fQuery’s setPassword:(missing value)
  
fQuery’s fetch:(missing value)
  
return {fQuery’s passwordObject(), eDic1}
  
–>  {​​​​​(NSDictionary) {​​​​​​​number:42, ​​​​​​​string:"Hello World"​​​​​}, ​​​​​(NSDictionary) {​​​​​​​number:42, ​​​​​​​string:"Hello World"​​​​​}​​​}
end testPasswordObject

★Click Here to Open This Script 

Posted in Keychain | Tagged 10.11savvy 10.12savvy 10.13savvy | 1 Comment

アプリケーションのBundle IDからアプリのAppleScript対応度を取得する

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

set aBundleID to "com.apple.Safari"
set aPath to retAppScriptabilityFromBundleID(aBundleID) of me
–>  true

–Bundle IDからアプリケーションのScriptabilityをbooleanで返す
on retAppScriptabilityFromBundleID(aBundleID)
  set appPath to current application’s NSWorkspace’s sharedWorkspace()’s absolutePathForAppBundleWithIdentifier:aBundleID
  
if appPath = missing value then return false
  
set aDict to (current application’s NSBundle’s bundleWithPath:appPath)’s infoDictionary()
  
set aRes to aDict’s valueForKey:"NSAppleScriptEnabled"
  
if aRes = missing value then return false
  
return aRes as boolean
end retAppScriptabilityFromBundleID

★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 2016-02-08 by Takaaki Naganoya
— 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"

set aBundleID to "com.apple.Safari"
set aPath to retAppIconPathFromBundleID(aBundleID) of me
–>  "/Applications/Safari.app/Contents/Resources/compass.icns"

–Bundle IDからアプリケーションアイコンのフルパスをPOSIX pathで返す
on retAppIconPathFromBundleID(aBundleID)
  –Bundle IDからアプリケーションへのパスを取得する
  
set appPath to current application’s NSWorkspace’s sharedWorkspace()’s absolutePathForAppBundleWithIdentifier:aBundleID
  
if appPath = missing value then return false
  
  
–Info.plistを読み込んで、iconのファイル名を取得
  
set aDict to (current application’s NSBundle’s bundleWithPath:appPath)’s infoDictionary()
  
set iconFile to aDict’s valueForKey:"CFBundleIconFile"
  
if iconFile = missing value then return false
  
  
–パスからバンドルを取得して、バンドル内の指定ファイルタイプのファイル名のパスを取得する
  
set aBundle to current application’s NSBundle’s bundleWithPath:appPath
  
set iconFullPath to aBundle’s pathForResource:iconFile ofType:"icns"
  
if iconFullPath = missing value then return false
  
  
return iconFullPath as string
  
end retAppIconPathFromBundleID

★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名:指定ファイルをオープンするデフォルト・アプリケーションのパスを求める
— 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 | Leave a comment

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

Post navigation

  • Older posts
  • Newer posts

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

Google Search

Popular posts

  • 開発機としてM2 Mac miniが来たのでガチレビュー
  • macOS 15, Sequoia
  • Pages本執筆中に、2つの書類モード切り替えに気がついた
  • Numbersで選択範囲のセルの前後の空白を削除
  • メキシカンハットの描画
  • Pixelmator Pro v3.6.4でAppleScriptからの操作時の挙動に違和感が
  • AppleScriptによる並列処理
  • Safariで「プロファイル」機能を使うとAppleScriptの処理に影響
  • macOS 15でも変化したText to Speech環境
  • AppleScript入門③AppleScriptを使った「自動化」とは?
  • デフォルトインストールされたフォント名を取得するAppleScript
  • macOS 15 リモートApple Eventsにバグ?
  • 【続報】macOS 15.5で特定ファイル名パターンのfileをaliasにcastすると100%クラッシュするバグ
  • AppleScript入門① AppleScriptってなんだろう?
  • macOS 14で変更になったOSバージョン取得APIの返り値
  • Script Debuggerの開発と販売が2025年に終了
  • NSObjectのクラス名を取得 v2.1
  • macOS 15:スクリプトエディタのAppleScript用語辞書を確認できない
  • 有害ではなくなっていたSpaces
  • AVSpeechSynthesizerで読み上げテスト

Tags

10.11savvy (1101) 10.12savvy (1242) 10.13savvy (1391) 10.14savvy (587) 10.15savvy (438) 11.0savvy (283) 12.0savvy (212) 13.0savvy (194) 14.0savvy (147) 15.0savvy (135) CotEditor (66) Finder (51) iTunes (19) 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 (55) 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
  • 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
  • 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年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