How do you do an include in applescript?

六眼飞鱼酱① 提交于 2019-12-11 07:34:00

问题


I have a bunch of code I want to to use in several different applescripts so I would like to put it into it's own applescript that I can reference from other applescripts. Basically I want to do an include. How is this done in applescript?


回答1:


Here is the best way I have found to accomplish this. You can call a function on another script like so:

script a.scpt

set myScript to load script "b.scpt"
set foo to myScript's theTest()

script b.scpt

on theTest()
       return true
end theTest

As you can see you can call functions within b.scpt from a.scpt by calling the function name myScript's theTest().




回答2:


You can put all the handlers and scripts that you want to reference inside a Script Library (for example: my_math_lib.scpt and my_string_lib.scpt). Then, save this file in a Script Libraries folder on your computer.

Depending on how you want to define the availability of this library, you use a different folder:

  • Place the my_math_lib.scpt and my_string_lib.scpt files inside the /Library/Script Libraries folder to make them available for all users on the computer.
  • Place them in the ~/Library/Script Libraries folder to make them available for a specific user only.

You can then use all the handlers in those libraries as follows:

property math_lib : script "my_math_lib"
property string_lib : script "my_string_lib"
math_lib's do_this()
string_lib's do_that()


来源:https://stackoverflow.com/questions/4311090/how-do-you-do-an-include-in-applescript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!