現在のアプリをログに記録し、別のアプリに切り替え、何らかのタスクを実行し、元のアプリに戻るスクリプトを作成しようとしています。これは私が持っているものです
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
奇妙なことに、文字列リテラルを入力すると activate application コマンドが機能しますが、文字列変数を渡すとアプリケーションがアクティブになりません。理由はありますか?