AppleScript名:指定のAppleScriptのソースを取得してOLD Style ASかASOCかを判定する v2 |
— Created 2017-06-03 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "OSAKit" set aFile to choose file of type {"com.apple.applescript.script", "com.apple.applescript.script-bundle"} set aRes to detectScriptIsPureASorASOC(aFile) of me –指定AppleScriptファイルがOLD Style ASかASOCかを判定して返す on detectScriptIsPureASorASOC(aFile) set sRes to getASsourceFor(aFile) of me set sName to scriptKind of sRes –Name set sText to scriptSource of sRes –Source if sText = "" or sText = missing value then return missing value if sName = "AppleScript" then if sText contains "use framework \"Foundation\"" then return true –ASOC else return false –Pure AppleScript end if else –JXAなど他のOSA言語の場合 return sName end if end detectScriptIsPureASorASOC –指定AppleScriptファイルのソースコードを取得する(実行専用Scriptからは取得できない) on getASsourceFor(anAlias as {alias, string}) set anHFSpath to anAlias as string set aURL to current application’s |NSURL|’s fileURLWithPath:(POSIX path of anHFSpath) set theScript to current application’s OSAScript’s alloc()’s initWithContentsOfURL:aURL |error|:(missing value) set scriptName to theScript’s |language|()’s |name|() as string set theSource to theScript’s source() as text return {scriptKind:scriptName, scriptSource:theSource} end getASsourceFor |
More from my site
(Visited 44 times, 1 visits today)