在 AppleScript 中复制文件

发布于 2024-10-19 14:25:24 字数 536 浏览 3 评论 0原文

我有下面的代码在 Applescript 中设置一个变量作为 iTunes 音乐文件夹的路径:

set username to text returned of (display dialog "RingtoneDude" default answer "Enter your path to your iTunes Ringtones folder here. e.g. /Users/David/Music/iTunes/iTunes Music/Ringtones" buttons {"Confirm", "Cancel"} default button 1)

然后我有代码调用变量 username 来复制文件,

tell application "Finder"
                copy file theCopy to username
            end tell

但文件 theCopy 位于桌面上(theCopy 是一个变量)不移动到该文件夹​​。

请帮忙。

I have the code below to set a variable in Applescript for the path to the iTunes Music Folder:

set username to text returned of (display dialog "RingtoneDude" default answer "Enter your path to your iTunes Ringtones folder here. e.g. /Users/David/Music/iTunes/iTunes Music/Ringtones" buttons {"Confirm", "Cancel"} default button 1)

And then I have the code to call the variable username to copy a file

tell application "Finder"
                copy file theCopy to username
            end tell

but the file theCopy which is on the desktop (theCopy is a variable) does not move to the folder.

Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

弥枳 2024-10-26 14:25:24

我相信您误解了 copy 命令。 copy 命令用于将一个变量的内容传输到另一个变量。您需要使用的是duplicate命令,该命令用于将文件复制到指定位置。它的语法如下:

duplicate [alias] to [alias]
   [replacing boolean] --If true, replaces files in the destination with the same name

话虽如此,您的新代码与 Uriah Carpenter 的答案相结合,应该如下所示:

set myRingtoneFolder to choose folder with prompt "Select your iTunes Ringtone folder:"
tell application "Finder" to duplicate theCopy to myRingtoneFolder

I believe you've misunderstood the copy command. The copy command is used for transferring the contents of one variable into another variable. What you need to use is the duplicate command, which is used for copying files to a specified location. Its syntax is as follows:

duplicate [alias] to [alias]
   [replacing boolean] --If true, replaces files in the destination with the same name

Having said that, your new code, in conjunction with Uriah Carpenter's answer, should look something like this:

set myRingtoneFolder to choose folder with prompt "Select your iTunes Ringtone folder:"
tell application "Finder" to duplicate theCopy to myRingtoneFolder
站稳脚跟 2024-10-26 14:25:24

我建议您使用 选择文件夹< /code>返回一个别名

要将某些文本设置为别名对象,请使用将 myAliasPath 设置为 myTextPath 作为别名

有关更多详细信息,请参阅别名和文件。

I would suggest you use choose folder which returns an alias.

To make some text into an alias object use set myAliasPath to myTextPath as alias.

For more detailed information see Aliases and Files in the AppleScript documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文