【问题标题】:AppleScript Droplet on DMG not workingDMG 上的 AppleScript Droplet 不起作用
【发布时间】:2010-08-12 07:37:40
【问题描述】:

嘿,我将以下 AppleScript 保存为 Droplet。 它保存在一个像这样的 DMG 文件中 http://dl.dropbox.com/u/1839051/TestDMG.dmg

问题是,虽然有些人可以将模板拖到 Droplet 上并使其正常工作,但当我尝试将模板拖到 Droplet 上时,会出现划掉的圆圈符号,表示无法执行此操作。什么都没有发生,文件没有被复制。

有谁知道我为什么会遇到这个问题以及如何解决它? 提前谢谢伙计。

on open thefiles    
  set outputFolder to (path to application support folder from user domain as text) & "iWork:Pages:Templates:My Templates:"
  do shell script "/bin/mkdir -p " & quoted form of POSIX path of outputFolder

  tell application "Finder"
    duplicate thefiles to outputFolder
  end tell    
end open

【问题讨论】:

    标签: shell applescript dmg


    【解决方案1】:

    与其使用 Droplet 并让用户将文件拖到 Droplet 上,为什么不直接制作一个安装程序,让用户只需双击安装程序?这会更容易,也可能会避免你的问题。我还在您的代码中添加了一些错误处理,因为使用运输代码这样做是明智的。我们还会告诉用户发生了什么。

    注意:您的代码中也有错误。 outputFolder 是一个字符串。 Finder 需要一个文件说明符。要使字符串成为说明符,您可以在字符串路径前添加单词“文件”或“文件夹”。您的代码可能有效,但编写它的正确方法是使用说明符。其他应用程序可能不采用字符串路径,但它们都会采用说明符......所以要养成使用它们而不是字符串的习惯。

    try
        -- create the output folder if necessary
        set outputFolder to (path to application support folder from user domain as text) & "iWork:Pages:Templates:My Templates:"
        do shell script "/bin/mkdir -p " & quoted form of POSIX path of outputFolder
    
        -- find the templates on the dmg disk
        set myPath to path to me
        tell application "Finder"
            set myContainer to container of myPath
            set templateFiles to (files of myContainer whose name extension is "template") as alias list
        end tell
    
        -- copy the templates to the output folder
        -- NOTE: the script will error if any of the templates already exist
        -- therefore we use a repeat loop and duplicate each file separately with a try block
        -- around it to avoid errors in case some templates have already been installed.
        tell application "Finder"
            repeat with aTemplate in templateFiles
                try
                    duplicate aTemplate to folder outputFolder
                end try
            end repeat
        end tell
    
        -- tell the user everything was OK
        tell me to activate
        display dialog "The templates were successfully installed! You may now use them in Pages." buttons {"OK"} default button 1 with title "Templates Installer" with icon note
    on error
        tell me to activate
        display dialog "There was an error installing the templates. Please manually install them by copying them to the following folder." & return & return & (POSIX path of outputFolder) buttons {"OK"} default button 1 with title "Templates Installer"
    end try
    

    【讨论】:

    • 谢谢。这是我使用 Applescript 编写的第一个脚本。我一回家就试试你的版本。我试图做一个安装程序,但我不知道如何在 DMG 上获取当前路径。到目前为止,谢谢。
    【解决方案2】:

    这看起来是一个权限问题,我不得不想知道那些可以和那些不能与他们运行的操作系统有关的差异。我以管理员身份运行 Mac OS 10.6,但无法在 DMG 中执行操作。但是,如果我将这两个文件从 DMG 中拖到我的桌面上,我就能够执行该操作。

    如果您需要在硬盘驱动器的特定位置安装文件以支持您的项目,那么我建议您制作一个安装程序(以及匹配的卸载程序),而不是您提供的设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多