如何找到正在执行的 AppleScript 的文件名 [英] How find the file name of an executing AppleScript
问题描述
如何找到正在执行的 AppleScript 的名称?
How do I find the name of an executing AppleScript?
原因:我想创建一个脚本,根据其文件名更改其行为.类似的东西:
REASON: I want to create a script that changes its behavior based on its filename. Something like:
if myname is "Joe" then ACTION1
else if myname is "Frank" then ACTION2
else ACTION3
推荐答案
获取名称的正常方法是使用我的名字".然而,applescripts 是由applescript runner 运行的,所以当你在脚本上使用它时,你会得到Applescript Runner"作为名称.如果您将脚本编译为应用程序,则我的名字"将起作用.获取脚本名称的唯一方法是获取其路径并提取名称.这样的东西因此适用于脚本......
The normal way to get the name is by using "name of me". However applescripts are run by applescript runner so when you use that on a script you get "Applescript Runner" as the name. If you compile your script as an application then "name of me" will work. The only way to get the script name is by getting its path and extracting the name. Something like this would thus work for scripts...
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
这篇关于如何找到正在执行的 AppleScript 的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!