首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DMG上的AppleScript Droplet不工作

DMG上的AppleScript Droplet不工作
EN

Stack Overflow用户
提问于 2010-08-12 15:37:40
回答 2查看 536关注 0票数 1

嘿,我已经将下面的AppleScript保存为一个Droplet。它被保存在一个DMG文件中,就像下面这个http://dl.dropbox.com/u/1839051/TestDMG.dmg

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

有没有人知道我为什么会有这个问题,以及如何解决它?先谢谢你,伙计。

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-08-12 20:21:50

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

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

代码语言:javascript
复制
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
票数 1
EN

Stack Overflow用户

发布于 2010-08-12 17:51:13

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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3465631

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档