使用字符串变量作为Applescript命令参数

时间:2013-04-01 21:30:50

标签: escaping applescript quotes

我正在尝试执行以下操作:

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

cleanup("name")

但是,由于x变量是一个字符串,因此clean up命令不接受它并退出并显示错误。有没有办法将字符串转换为命令接受的东西或其他解决方案取消引用变量而不使用if,else语句如下:

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 个答案:

答案 0 :(得分:2)

这应该有用。

    on cleanup(x)

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



end cleanup

cleanup("name")

来自 StandardAdditions

运行脚本v:运行指定的脚本或脚本文件

  • 运行脚本脚本:脚本文本(或别名或文件引用) 要运行的脚本文件

    • [参数列表为任何]:参数列表

    • [in text]:要使用的脚本组件; default是当前的脚本组件

→any:运行脚本的结果

相关问题