1

嘿,我将以下 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
4

2 回答 2

1

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

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

于 2010-08-12T09:51:13.223 回答
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
于 2010-08-12T12:21:50.043 回答