Applescript - 以Script或Application ...的形式返回不同的值...?
问题描述:
我得到了一些代码,寻找丢失的字体。 当它返回“已安装”或“不可用”的脚本 当它返回一个应用«不断**** FSIN»或«不变**** fsNA»Applescript - 以Script或Application ...的形式返回不同的值...?
我想一个解决办法是只是使它看起来为FSIN代替,但我还是想了解什么是在这里发生了......
tell application id "com.adobe.InDesign"
tell active document
set fontStatus to (status of every font)
repeat with s in fontStatus
display dialog (s as string)
end repeat
end tell
end tell
答
display dialog
属于标准添加这是一个不同的范围。 尝试设置常数变量在InDesign
tell application id "com.adobe.InDesign"
tell active document
set fontStatus to (status of every font)
repeat with s in fontStatus
set fontStatusString to s as string
display dialog fontStatusString
end repeat
end tell
end tell
答
的范围内,是正常的。 Apple事件使用“四字符代码”,而不是人类可读的名字。 在脚本编辑器中运行脚本时,AppleScript已经加载了应用程序的术语(因为它需要从源代码编译AS脚本),因此可以使用它将这些代码转换回人类可读的名称。
当您将AS脚本作为独立应用程序保存时,它已被编译,因此应用程序的术语在默认情况下不会被加载。您可以使用一个条件块:
repeat with aConstantRef in fontStatus
set theConstant to contents of aConstantRef
if theConstant is installed then
set constantName to "installed"
else if theConstant is not available then
set constantName to "not available"
...
else -- catch-all in case you miss any
set constantName to theConstant as string
end if
end repeat
,或者您可以通过包括run script
命令编译一个“假”脚本针对该应用程序强制的AppleScript在运行时加载应用程序的术语:
run script "tell application id \"com.adobe.InDesign\" to (not available)"
之后,该术语也应可用于您的主要脚本。