DMG上的AppleScript Droplet无法正常工作

时间:2010-08-12 07:37:40

标签: shell applescript dmg

嘿我将以下AppleScript保存为Droplet。 它保存在像http://dl.dropbox.com/u/1839051/TestDMG.dmg

这样的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

2 个答案:

答案 0 :(得分:1)

这看起来是一个权限问题,我不得不怀疑那些能够和那些无法与他们正在运行的操作系统有关的人之间的差异。我作为管理员运行Mac OS 10.6,我无法在DMG中执行操作。但是,如果我将两个文件从DMG中拖出到我的桌面上,我就能够执行操作。

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

答案 1 :(得分:1)

不是使用Droplet并让用户将文件拖到Droplet上,为什么不只是创建一个安装程序,以便用户只需要双击安装程序?它会更容易,也可能避免你的问题。我还在您的代码中添加了一些错误处理,因为使用传送代码执行此操作只是谨慎。我们还告诉用户发生了什么。

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

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