【问题标题】:Use string variable as Applescript command argument使用字符串变量作为 Applescript 命令参数
【发布时间】:2013-04-01 21:30:50
【问题描述】:

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

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

cleanup("name")

然而,由于 x 变量是一个字符串,清理命令不接受它并以错误退出。有没有办法将字符串转换为命令接受的字符串或其他解决方案来取消引用变量而不使用 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")

【问题讨论】:

    标签: escaping applescript quotes


    【解决方案1】:

    这应该可行。

        on cleanup(x)
    
        run script "tell application \"Finder\" to  clean up window 1 by " & space & x
    
    
    
    end cleanup
    
    cleanup("name")
    

    来自 StandardAdditions 库

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

    • run script script :脚本文本(或别名或文件引用 脚本文件)运行

      • [带任意参数列表]:参数列表

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

    → any : 运行脚本的结果

    【讨论】:

      猜你喜欢
      • 2013-04-03
      • 2022-12-02
      • 2020-08-19
      • 2017-02-02
      • 2015-12-26
      • 2015-08-10
      • 1970-01-01
      • 2019-10-01
      • 1970-01-01
      相关资源
      最近更新 更多