开发者

AppleScript Droplet on DMG not working

Hey I have the following AppleScript saved as a Droplet. It is saved on a DMG file like this one http://dl.dropbox.com/u/1839051/TestDMG.dmg

The Problem is, while some can drag the template onto the Droplet and have it working, when I try to drag the template onto the droplet the crossed-out circle-symbol shows up indicating that this action is not possible. Nothing happens, the file is not copied.

Does anyone have any idea why I have this problem and how it can be fixed? Thanks in advance guy.

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 ope开发者_运维技巧n


Rather than using a droplet and having the user to drag the files onto the droplet, why not just make an installer so the user only has to double-click the installer? It would be easier and also probably avoid your problem. I also added some error handling in your code because it's just prudent to do that with shipping code. We also tell the user what happened.

NOTE: you also had an error in your code. The outputFolder is a string. The Finder requires a file specifier. To make the string into a specifier you add either the word "file" or "folder" in front of the string path. Your code may have worked but the proper way to write it is with a specifier. Other applications may not take the string path but they will all take the specifier... so get in the habit of using them instead of strings.

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


This looks to be a permissions issue, and I have to wonder if the differential between those who can and those who can't have something to do with which OS they are running. I'm running Mac OS 10.6 as an administrator and I was unable to perform the action in the DMG. But I was able to perform the action if I dragged both files out of the DMG and onto my Desktop.

If you need to install files in specific locations to the hard drive to support your project, then I would recommend making an installer (and a matching uninstaller as well) as opposed to the setup you have presented.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜