代码之家  ›  专栏  ›  技术社区  ›  Lukas Oppermann

DMG上的AppleScript水滴不工作

  •  1
  • Lukas Oppermann  · 技术社区  · 15 年前

    它保存在像这样的DMG文件中 http://dl.dropbox.com/u/1839051/TestDMG.dmg

    问题是,虽然有些人可以将模板拖到液滴上并使其工作,但当我尝试将模板拖到液滴上时,会出现一个划掉的圆符号,表示此操作不可能。什么也没发生,文件没有被复制。

    提前谢谢,伙计。

    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 回复  |  直到 15 年前
        1
  •  1
  •   regulus6633    15 年前

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

    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
    
        2
  •  1
  •   Philip Regan    15 年前

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