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"} )
);
我希望这可以帮助您入门!
@朱利安