为了运行我的AppleScript程序,我必须打开它并选择“运行”。我希望程序在我单击它时就能自动运行。我尝试将其编译,但似乎没有任何改变或创建新文件。
2种方法。
1)我首选的方法是激活脚本菜单。如果您使用的是10.6版本,请打开AppleScript编辑器,然后打开偏好设置,在常规选项卡下点击“在菜单栏中显示脚本菜单”。现在你将在屏幕右上角的菜单栏区域得到一个新图标。你可以从那个菜单运行任何AppleScript。(在10.5中的过程不同,但你可以谷歌查找方向)。要将一个AppleScript放入该菜单中,只需转到文件夹~/Library/Scripts并添加您的AppleScript即可。从脚本菜单中选择您的AppleScript将运行它。
2)从AppleScript编辑器中的文件菜单中选择“另存为...”,并将“文件格式”设置为应用程序。然后它就像任何其他应用程序一样工作......只需双击它来运行它。
注意:如果使用脚本菜单...选择一个脚本将运行它。如果您想打开AppleScript编辑器以编辑脚本,则在选择脚本时按住Option键。
当您保存AppleScript时,可以选择将其保存为应用程序,这将使其可执行。
如果正确保存,就是一个可点击的应用程序:
# Old post but this answer may save someone a lot of time.
# In Applescript, make a new script with the following lines (see below).
# Then, after selecting the ''Stay open after run handler'' option,
# save as File Format ''application'' .
# This is the simplest version of a standalone app.
# It is essentially a directory with a Scripts folder and a compiled Applet in it.
# Right click it's icon in the Finder to open the package for a peek inside.
# Other internal items such as icons, files, and other scripts may be added and interacted with.
on run
#put something here which happens once at startup.
say "I am running."
end run
on idle
#put something here which happens repeatedly.
say "I am waiting."
return 2 --repeats every 2 seconds. (0 will default to 30 seconds)
end idle
on quit
#put something here which happens at the end of the program's use.
say "I am quitting."
continue quit
end quit
# To accept dropped item's, embed your handlers between tags before saving as shown below here. Enjoy!
on open droppedItems
beep --or some other cool thing.
end open