Use string variable as Applescript command argument

陌路散爱 提交于 2021-01-28 07:25:00

问题


I'm trying to do the following:

on cleanup(x)
   tell application "Finder"    
      clean up window 1 by x
   end tell
end cleanup

cleanup("name")

However since x variable is a string, the clean up command doesn't accept it and exits with error. Is there a way to convert the string to something that the commands accepts or some other solution to unquote the variable without using if, else statements like this:

on cleanup(x)
   tell application "Finder"
      if x is "name" then
          clean up window 1 by name
      end if
   end tell
end cleanup

cleanup("name")

回答1:


This should work.

    on cleanup(x)

    run script "tell application \"Finder\" to  clean up window 1 by " & space & x



end cleanup

cleanup("name")

From the StandardAdditions Library

run script v : Run a specified script or script file

  • run script script : the script text (or an alias or file reference to a script file) to run

    • [with parameters list of any] : a list of parameters

    • [in text] : the scripting component to use; default is the current scripting component

→ any : the result of running the script



来源:https://stackoverflow.com/questions/15752249/use-string-variable-as-applescript-command-argument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!