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

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

问题描述

我正在使用特权javascript,该javascript可以访问python,如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,只是为我的Mac用户编码.

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

推荐答案

您将要使用命令行工具osacompile创建一个已编译的applescript文件.您可以查看其手册页以查看所有选项,但这很简单.例如,假设您想将以下applescript代码写入文件...

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并在每行代码之前使用"-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"选项,则可以使用echo ...来传递代码文本.

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的命令行工具.在此处找到它.页面上有指示.

The saved file will have the default applescript icon. If you also want to change its icon you can use a command line tool I wrote called SetFileIcon. Find it here. There's directions on the page.

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

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