JMP 15 AppleScript 運行程序()我以前從未使用過 Run Program(),我需要一些幫助。 由於 JMP 無法打開受密碼保護的 Excel 文件,因此我正在編寫一些 Applescript 來打開它們並將其導出為不受保護的 .csv。 我想從 JSL 腳本中運行此 Applescript。 也許如果它運行良好,我將創建一個小的 JMP 用戶函數來包裝它,這樣我就可以在 JMP 中模擬打開受密碼保護的 Excel 的功能。
但是……我在爭論 Run Program() 時遇到了麻煩。 幾個問題。
1. 我的 Applescript 應該保存為應用程序(.app 擴展名)還是腳本(.scpt 擴展名)。
2. 我的 JSL 語法如下所示:
Run Program( Executable( "Users/me/Desktop/myscript.scpt" ) )
但它不起作用,給出以下錯誤:
launch path not accessible in access or evaluation of 'Glue' , Names Default To Here( 1 ); /*###*/Run Program(
Executable( "/Users/me/Desktop/re.scpt" )
) /*###*/;
In the following script, error marked by /*###*/
Names Default To Here( 1 ); /*###*/Run Program(
Executable( "/Users/me/Desktop/re.scpt" )
) /*###*/;
再次,我嘗試使用 .app 和 .scpt,但根本沒有擴展名 - 沒有樂趣。
顯然,我必須添加一些額外的代碼來處理生成的 .csv 導出文件,但現在,我只需要開始運行準系統 Applescript 即可。
謝謝你的幫助。
回复:JMP 15 AppleScript 運行程序()謝謝,朱利安。
這是一個稍微改進的版本,它允許您通過將 KM“將系統剪貼板設置為文本...”操作作為 KM 腳本的最後一個操作來從 KM 宏返回值。 然後,JSL 函數使用剪貼板內容作為其函數返回值。
另外,我意識到您不必使用 KM 宏 UUID;如果您只使用 KM 宏的普通名稱,它也同樣有效。
Add Custom Functions(
New Custom Function(
"ex",
"Run KMScript",
Function( {scriptID, paramlist = {}},
{paramstring, savedClipboard, macroResult = ""},
paramstring = Concat Items( paramlist );
savedClipboard = Get Clipboard();
Run Program(
Executable( "/usr/bin/osascript" ),
Options(
"-e tell application \!"Keyboard Maestro Engine\!" to do script \!"" || scriptID || "\!" with parameter \!"" || paramstring ||
"\!""
)
);
macroResult = Get Clipboard();
Set Clipboard( savedClipboard );
Return( macroResult );
)
) << Prototype( "ex:Run KMScript( scriptID as string, < {param1 as string, param2 as string, etc.} > )" ) << Parameter( "String", "scriptID" )
<< Parameter( "List", "parameter(s)" ) << Formula Category( "Utility" ) << Description(
"Runs a Keyboard Maestro (KM) script. The KM scriptID is either the KM macro's name or UUID. (You can reveal and copy the UUID by opening the 'Or trigger by shell script' text box at the top of your KM macro window.) The (optional) parameters to the KM script can be retrieved inside the KM macro using the KM '%TriggerValue%' token. KM receives them as a single concatenated string of space-separated values. If you want to return a value from KM, push it to the system clipboard before exiting the macro. This function will grab the clipboard contents and use as the function return value. (The function saves and restores the pre-invocation clipboard state, so the system clipboard is unaffected by the function.)"
)
);回复:JMP 15 AppleScript 運行程序()這太棒了,約翰! 很高興你分享這個,我相信這會對某人有所幫助。
@朱利安回复:JMP 15 AppleScript 運行程序()對此進行一點跟進,也許一些 Mac 用戶可能會覺得有用。
Applescript 的想法沒有成功——不是因為 JSL,而是因為 OSX 10.15 下 MSExcel applescripting 的限制。 (Excel 中的保存命令不再正常工作,顯然是由於沙箱的原因;我被告知 Microsoft 需要更新其 Applescript 支持。 )
相反,我決定使用 Keyboard Maestro (KM) 編寫我需要的腳本,這是一個非常好的 OSX 腳本/宏應用程序。 (我強烈推薦它——我沒有利益衝突。)
我在KM中寫了我需要的腳本。 然後我編寫了一個調用 KM 腳本的 JSL 函數:
Add Custom Functions(
New Custom Function(
"ex",
"Run KMScript",
Function( {scriptID, paramlist = {}},
{paramstring},
paramstring = Concat Items( paramlist );
Run Program(
Executable( "/usr/bin/osascript" ),
Options(
"-e tell application \!"Keyboard Maestro Engine\!" to do script \!"" || scriptID || "\!" with parameter \!"" || paramstring ||
"\!""
)
);
)
) << Prototype( "ex:Run KMScript( scriptID as string, < {param1 as string, param2 as string, etc.} > )" ) << Parameter( "String", "scriptID" ) <<
Parameter( "List", "parameter(s)" ) << Formula Category( "Utility" ) << Description(
"Runs a Keyboard Maestro script. The KM scriptID is a UUID; you can reveal and copy it by opening the 'Or trigger by shell script' text box at the top of your KM macro window. The (optional) parameters to the KM script can be retrieved inside the KM macro using the KM '%TriggerValue' token. KM receives them as a single concatenated string of space-separated values."
)
);現在,我在 JSL 中使用它來調用 KM 宏,該宏在 Numbers 中打開受保護的 Excel 文件,取消保護,將其另存為 csv,在 JMP 中打開它,然後關閉 Numbers。 效果很好。
希望其他人可能會發現這很有用。
回复:JMP 15 AppleScript 運行程序()完美的!! 謝謝!!!回复:JMP 15 AppleScript 運行程序()你好@約翰_馬登,
我會將您的腳本保存為 .app,然後使用類似以下內容的內容來打開該應用程序,該應用程序使用“open”可執行文件來打開 .app:
Run Program(
Executable( "/usr/bin/open"),
options( {"/users/me/Desktop/myscript.app"} )
);
我希望這可以幫助您入門!
@朱利安