编程方式创建Apple脚本 [英] Programatically Create Apple Script

查看:119
本文介绍了编程方式创建Apple脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的JavaScript privelaged有权访问蟒蛇一样的ctypes和整个MAC API。

I am using privelaged javascript which has access to python like ctypes and the whole mac api.

编程我试图创建一个AppleScript文件,并设置其图标。

Programmatically I'm trying to create an applescript file and set its icon.

我想按照这个教程在这里就如何使在Mac电脑上的个人资料的快捷方式:
http://weblogs.mozillazine.org/asa/archives/2008/08 /shortcut_to_lau.html

I'm trying follow this tutorial here on how to make profile shortcuts on macs: http://weblogs.mozillazine.org/asa/archives/2008/08/shortcut_to_lau.html

这是为创建一个文本文件,并与一些文字填充它简单?

Is this as simple as creating a text file and populating it with some text?

我没有一个苹果,只编码我的Mac用户。

I dont have a mac, just coding for my mac users.

感谢

推荐答案

您需要使用命令行工具osacompile创建一个编译的AppleScript文件。你可以看一下它的手册页查看所有选项,但它是相当简单的。例如,假设你想下面的AppleScript code写入一个文件...

You'll want to use the command line tool osacompile to create a compiled applescript file. You can look at its man page to see all your options but it's rather simple. For example, suppose you wanted to write the following applescript code to a file...

tell application "Safari"
    activate
end tell

您可以用osacompile使用code的每一行前的-e选项做到这一点。请注意,我把单引号括起来每行了。

You can do it with osacompile and using the "-e" option before each line of code. Note that I put single quotes around each line too.

set savePath to (path to desktop as text) & "test.scpt"

do shell script "osacompile -e 'tell application \"Safari\"' -e 'activate' -e 'end tell' -o " & quoted form of POSIX path of savePath

如果你不喜欢的-e选项,你可以管使用code文本回声...

If you don't like the "-e" option, you could pipe the code text using echo...

set scriptText to "tell application \"Safari\"
activate
end tell"

set savePath to (path to desktop as text) & "test.scpt"

do shell script "echo " & quoted form of scriptText & " | osacompile -o " & quoted form of POSIX path of savePath

保存的文件将默认的AppleScript图标。如果你也想改变它的图标,你可以使用命令行工具,我编写了一个名为SetFileIcon。搜寻这里。有在页面上的方向。

这篇关于编程方式创建Apple脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆