使用字符串变量作为Applescript命令参数 [英] Use string variable as Applescript command argument
问题描述
我正在尝试执行以下操作:
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")
但是,由于x变量是一个字符串,因此清理命令不接受它,并以错误退出.有没有一种方法可以将字符串转换为命令可以接受的内容,或者采用其他解决方案取消对变量的引用,而无需使用if,else语句,如下所示:
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")
推荐答案
这应该有效.
on cleanup(x)
run script "tell application \"Finder\" to clean up window 1 by " & space & x
end cleanup
cleanup("name")
从 StandardAdditions 库
运行脚本v:运行指定的脚本或脚本文件
run script v : Run a specified script or script file
-
运行脚本script:脚本文本(或指向的别名或文件引用)脚本文件)运行
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]:要使用的脚本组件;默认是当前脚本组件
[in text] : the scripting component to use; default is the current scripting component
→any:运行脚本的结果
→ any : the result of running the script
这篇关于使用字符串变量作为Applescript命令参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!