如何找到正在执行的 AppleScript 的名称?
原因:我想创建一个根据文件名更改其行为的脚本。就像是:
if myname is "Joe" then ACTION1
else if myname is "Frank" then ACTION2
else ACTION3
获取名字的正常方法是使用“我的名字”。然而,applescripts 是由 applescript runner 运行的,因此当您在脚本上使用它时,您会得到“Applescript Runner”作为名称。如果您将脚本编译为应用程序,那么“我的名字”将起作用。获取脚本名称的唯一方法是获取其路径并提取名称。因此,这样的东西适用于脚本......
getMyName()
tell me to display dialog result
on getMyName()
set myPath to path to me as text
if myPath ends with ":" then
set n to -2
else
set n to -1
end if
set AppleScript's text item delimiters to ":"
set myName to text item n of myPath
if (myName contains ".") then
set AppleScript's text item delimiters to "."
set myName to text 1 thru text item -2 of myName
end if
set AppleScript's text item delimiters to ""
return myName
end getMyName
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)