Applescript - Returns 脚本与应用程序的不同值...?
Applescript - Returns different values as Script vs Application ...?
我得到了一些查找缺失字体的代码。
如果是脚本,则 returns "installed" 或 "not available"
当它是一个应用程序时,它 returns «constant ****fsIn» 或 «constant ****fsNA»
我想一个解决方法是让它查找 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 事件使用 "four-char codes",而不是人类可读的名称。
当您在脚本编辑器中 运行 脚本时,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
或者您可以强制 AppleScript 在 运行 时间加载应用程序的术语,方法是包含编译针对该应用程序的 'dummy' 脚本的 run script
命令:
run script "tell application id \"com.adobe.InDesign\" to (not available)"
之后该术语也应该适用于您的主脚本。
我得到了一些查找缺失字体的代码。 如果是脚本,则 returns "installed" 或 "not available" 当它是一个应用程序时,它 returns «constant ****fsIn» 或 «constant ****fsNA»
我想一个解决方法是让它查找 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 事件使用 "four-char codes",而不是人类可读的名称。 当您在脚本编辑器中 运行 脚本时,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
或者您可以强制 AppleScript 在 运行 时间加载应用程序的术语,方法是包含编译针对该应用程序的 'dummy' 脚本的 run script
命令:
run script "tell application id \"com.adobe.InDesign\" to (not available)"
之后该术语也应该适用于您的主脚本。