Shell DMG上的AppleScript液滴不工作
嘿,我把下面的AppleScript保存为水滴。 它保存在像这样的DMG文件中 问题是,虽然有些人可以将模板拖到液滴上并使其工作,但当我尝试将模板拖到液滴上时,会显示一个略去的圆圈符号,指示此操作不可能。不会发生任何情况,文件不会被复制 有人知道我为什么会有这个问题,以及如何解决这个问题吗? 提前谢谢你,伙计Shell DMG上的AppleScript液滴不工作,shell,applescript,dmg,Shell,Applescript,Dmg,嘿,我把下面的AppleScript保存为水滴。 它保存在像这样的DMG文件中 问题是,虽然有些人可以将模板拖到液滴上并使其工作,但当我尝试将模板拖到液滴上时,会显示一个略去的圆圈符号,指示此操作不可能。不会发生任何情况,文件不会被复制 有人知道我为什么会有这个问题,以及如何解决这个问题吗? 提前谢谢你,伙计 on open thefiles set outputFolder to (path to application support folder from user domai
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
这看起来是一个权限问题,我想知道那些可以和那些不能的人之间的区别是否与他们正在运行的操作系统有关。我以管理员身份运行Mac OS 10.6,无法在DMG中执行该操作。但是,如果我将这两个文件从DMG拖到桌面上,我就能够执行该操作
如果您需要在硬盘驱动器的特定位置安装文件以支持您的项目,那么我建议您使用安装程序(以及匹配的卸载程序),而不是您提供的安装程序 与其使用droplet并让用户将文件拖到droplet上,为什么不制作一个安装程序,以便用户只需双击安装程序?这会更容易,也可能避免你的问题。我还在代码中添加了一些错误处理,因为使用装运代码这样做是明智的。我们还会告诉用户发生了什么 注意:您的代码中也有一个错误。outputFolder是一个字符串。查找程序需要一个文件说明符。要使字符串成为说明符,可以在字符串路径前面添加单词“file”或“folder”。您的代码可能已经运行,但正确的编写方法是使用说明符。其他应用程序可能不采用字符串路径,但它们都将采用说明符。。。所以要养成使用它们而不是字符串的习惯
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
谢谢这是我用Applescript编写的第一个脚本。我回家后会试试你的版本。我试着做一个安装程序,但我不知道如何获得DMG上的当前路径。谢谢你。