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

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

问题描述

我正在使用私有 javascript,它可以访问像 ctypes 和整个 mac api 这样的 python.

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天全站免登陆