【问题标题】:How to make an executable program from AppleScript如何从 AppleScript 制作可执行程序
【发布时间】:2011-04-12 11:55:01
【问题描述】:

为了运行我的 AppleScript 程序,我必须打开它并选择“运行”。我希望程序在我单击它时运行。我试图编译它,但它似乎没有任何区别或创建一个新文件。

【问题讨论】:

    标签: osx-snow-leopard applescript executable


    【解决方案1】:

    如果保存正确,则为可点击的应用程序:

    # 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
    

    【讨论】:

    • OP 只是想知道如何保存他的 AppleScript script,默认情况下保存为 .scpt 文件,作为一个应用程序,因此它不会在脚本编辑器中持续打开,而必须单击运行。 -- 不是如何构造他已经工作的代码
    • 它不会替换 OP 的代码,它是 OP 想要作为应用程序运行的任何代码的包装器。以“#put something here...”开头的部分是放置 OP 现有代码的位置。 “运行”、“空闲”和“退出”处理程序是 Apple 将 Applescripts 转换为可运行应用程序的标准方式,如 OP 的 2 个要求“运行我的 AppleScript 程序”和“当我点击它时运行”。 OP 的代码被插入其中一个处理程序(或放入应用程序包内自动生成的“脚本”文件夹中)。这就是“如何从 AppleScript 制作可执行程序”。
    • Applescript 可以运行的 3 种基本方式是:[1] 在脚本编辑器中,[2] 在 osascript 应用程序(菜单栏的脚本菜单)中,[3] 作为扩展名为“.app”的小程序.要将applescripts 保存为点击运行应用程序,它们需要一个运行处理程序。如果你想让一个继续运行,它需要一个空闲处理程序。如果你想让它退出,那么它需要一个退出处理程序。所有3个都包含在我的答案中。由于这可以在后台静默运行,因此我添加了语音以证明它正在运行,否则 OP 将不知道该应用程序是否正常运行。然后它可以被拖到 Dock 并在那里运行,因为现在它是一个真正的应用程序!
    【解决方案2】:

    当您保存 AppleScript 时,您可以选择将其保存为应用程序,这将使其可执行。

    【讨论】:

    • 如果脚本文件已经存在,您可能无法获得“另存为”选项(仅“保存”),在这种情况下,您可能不得不通过选择重复来欺骗它。然后你会得到文件格式的对话框。
    • 您也可以文件->导出为应用程序
    • 值得一提的是,一个 133 字节的脚本被保存为一个 101 字节的应用程序:[.
    【解决方案3】:

    如果您正在考虑 regulus6633 提到的第一个方法,您可以使用 Quicksilver、TextExpander、osascript 等启动 AppleScripts。要制作应用程序,您只需使用方法 2。

    【讨论】:

      【解决方案4】:

      两种方式。

      1) 我的首选方法是激活脚本菜单。如果您使用的是 10.6,请打开 AppleScript Editor。打开首选项并在“常规”选项卡下单击“在菜单栏中显示脚本菜单”。现在,您将在屏幕右上角的菜单栏部分看到一个新图标。您可以从该菜单运行任何 AppleScript。 (在 10.5 中,过程有所不同,但您可以 google 查找路线)。要在该菜单中放置一个 AppleScript,只需转到文件夹 ~/Library/Scripts 并将您的 AppleScript 添加到其中。从 Script 菜单中选择您的 applescript 将运行它。

      2) 从 AppleScript 编辑器的文件菜单中选择“另存为...”,并将“文件格式”设置为应用程序。然后它就像任何其他应用程序一样工作......只需双击它即可运行它。

      注意:如果您使用脚本菜单...选择一个脚本将运行它。如果您想在 AppleScript Editor 中打开脚本进行编辑,请在选择脚本时按住 option 键。

      【讨论】:

      • 请注意:它是 AppleScript 编辑器,而不是 Automator。
      猜你喜欢
      • 1970-01-01
      • 2021-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-09
      • 2023-03-23
      相关资源
      最近更新 更多