我正在尝试编写一个脚本来记录当前应用程序,切换到另一个应用程序,执行一些任务,然后返回到原始应用程序。这就是我所拥有的
set currentApp to my getCurrentApp()
activate application "Safari"
# Some task
activate application currentApp
to getCurrentApp()
set front_app to (path to frontmost application as Unicode text)
set AppleScript's text item delimiters to ":"
set front_app to front_app's text items
set AppleScript's text item delimiters to {""} --> restore delimiters to default value
set item_num to (count of front_app) - 1
set app_name to item item_num of front_app
set AppleScript's text item delimiters to "."
set app_name to app_name's text items
set AppleScript's text item delimiters to {""} --> restore delimiters to default value
set MyApp to item 1 of app_name
return MyApp
end getCurrentApp
奇怪的是,如果您输入字符串文字,则激活应用程序命令可以工作,但如果您将字符串变量传递给它,它将不会激活应用程序。任何想法为什么?