2010-08-12 31 views
1

嘿,我有以下的AppleScript保存为一个液滴。 它保存在DMG文件像这样的http://dl.dropbox.com/u/1839051/TestDMG.dmgAppleScript的液滴在DMG不工作

的问题是,有些可以拖动模板到滴和有工作,当我尝试将模板拖到液滴叉的circle-符号出现,表示此操作不可行。没有任何反应,该文件不被复制。

没有人有任何想法,为什么我有这样的问题,如何可以解决吗? 先谢谢了。

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 

回答

1

而不是使用液滴和让用户将文件拖动到液滴,为什么不只是做一个安装程序,因此用户只需双击安装程序?这会更容易,也可能避免你的问题。我还在代码中添加了一些错误处理,因为在运输代码中这样做是谨慎的。我们还告诉用户发生了什么事。

注意:您也有一个错误在你的代码。 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 
+0

感谢。这是我第一次使用Applescript的脚本。一旦我回家,我会尝试你的版本。我试图做一个安装程序,但我无法弄清楚如何获取DMG上的当前路径。 感谢迄今。 – 2010-08-12 14:32:46

+0

它工作得很好。非常感谢。 – 2010-08-12 19:06:56

1

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

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