2017-10-10 42 views
0

我得到了一些代碼,尋找丟失的字體。 當它返回「已安裝」或「不可用」的腳本 當它返回一個應用«不斷**** 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 

回答

2

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 
0

的範圍內,是正常的。 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)" 

之後,該術語也應可用於您的主要腳本。