如何使用AppleScript在桌面上创建一个文件夹并将拖放的文件移动到其中?

发布于 2024-10-28 15:20:40 字数 261 浏览 4 评论 0原文

我想做一个Applescript。我想在其上放置一个文件(.app 文件),并且它应该在与放置的文件相同的目录中创建一个名为“Payload”的文件夹。比它应该复制拖放到 Payload 文件夹中的文件。 Payload 文件夹现在应该被压缩。扩展名应从 .zip 更改为 .ipa。现在,.ipa 文件应重命名为拖放文件的文件名。最后,它应该删除创建的文件夹(如果还没有),并且删除的项目也应该被删除。

我该怎么做?

非常感谢。

没明白吗?请发表评论。 :)

I want to make an Applescript. I want to drop a file on it (.app file) and than it should create a folder named "Payload" in the same directory as file that was dropped. Than it should copy the file that was dropped to the Payload folder. The Payload folder should now be zipped. Than the extension should be changed from .zip to .ipa. And the .ipa file should now be renamed to the file name that the droppped file has. And at the end it should delete the folder that was created (if not already) and the dropped item should be deleted too.

How can I do this?

Thank you very much.

Didn't understand it? Please drop a comment. :)

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

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

发布评论

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

评论(3

临走之时 2024-11-04 15:20:40

首先,我假设您正在使用告诉应用程序“Finder” 步骤编写 Finder 脚本。如果是这种情况,请查看 Finder 字典中的 move 命令来移动文件,并查看 delete 来删除文件。

关于压缩,当我需要使用AppleScript压缩文件时,我发现使用带有do shell script的shall命令和zip命令行工具(输入man zip 在终端窗口中或查看 在线手册页)。

如果您不熟悉 movedeletedo shell script,请查看 Finder 的 AppleScript 字典(对于 move< /code> 和 delete 以及标准脚本添加(用于 do shell 脚本)。

First of all, I'm assuming that you're scripting the Finder with a tell application "Finder" step. If that's the case, check out the move command in the Finder's dictionary to move the file, and delete for removing the file.

Regarding zipping, when I've needed to compress a file with AppleScript, I've found that using a shall command with do shell script and the zip command line tool (type man zip in a Terminal window or take a look at the online man page).

If you're unfamiliar with move, delete and do shell script, check out the AppleScript dictionary for the Finder (for move and delete and the Standard Scripting Addition (for do shell script).

秋意浓 2024-11-04 15:20:40

结合查克的回答,您可以使用 文件夹操作来完成此操作...

In conjunction with Chuck's answer, you could use Folder Actions to accomplish this...

小梨窩很甜 2024-11-04 15:20:40

您可以使用“文件夹”操作作为答案来完成此操作

。首先,创建文件夹。

Puis,编写此 AppleScript

on adding folder items to theAttachedFolder after receiving theNewItems
-- Get the name of the attached folder
tell application "Finder"
    set theName to name of theAttachedFolder

    -- Count the new items
    set theCount to length of theNewItems

    -- Display an alert indicating that the new items were received
    activate
    display alert "Attention!" message (theCount & " new items were detected in folder " & (quoted form of theName) & "." as string)

    -- Loop through the newly detected items
    repeat with anItem in theNewItems

        -- Process the current item

        -- Move the current item to another folder so it's not processed again in the future

    end repeat
end tell
end adding folder items to

说明,将文件夹操作添加到文件夹:

观看文件夹说明

或者在 Automator 中,您可以使用此代码添加 AppleScript,您只需从 automator 设置一个变量并将其返回到AppleScript,用于您放入 targetFolder 中的文件夹。

set theFolder to "Folder_child:Folder_Grandchild:Folder_Great-Grandchild"
set theNewFolder to "Folder_First_Great_Grandchild"

if FolderExists(theFolder) = true then

    --display dialog "Exists " & theFolder & " !"
    --delete the file
else

    --display dialog "Missing " & theFolder & " !"
    -- do nothing or something else
end if

--handler for checking if exists theFolder/thePath

on FolderExists(theFolder) -- (String) as Boolean
    tell application "System Events"
        if exists folder theFolder then
            return true
        else
            return false
        end if
    end tell
end FolderExists

这就是我目前找到的全部内容。

此致

You can do that with a Folder action as the anwser up

First, create your folder.

Puis, write this AppleScript

on adding folder items to theAttachedFolder after receiving theNewItems
-- Get the name of the attached folder
tell application "Finder"
    set theName to name of theAttachedFolder

    -- Count the new items
    set theCount to length of theNewItems

    -- Display an alert indicating that the new items were received
    activate
    display alert "Attention!" message (theCount & " new items were detected in folder " & (quoted form of theName) & "." as string)

    -- Loop through the newly detected items
    repeat with anItem in theNewItems

        -- Process the current item

        -- Move the current item to another folder so it's not processed again in the future

    end repeat
end tell
end adding folder items to

Instructions for adding a folder action to a folder:

Watching Folders Instructions

Or In Automator you can add an AppleScript with this code, you just need to set a variable, from automator and return it to AppleScript, for the folder you dropped in the targetFolder.

set theFolder to "Folder_child:Folder_Grandchild:Folder_Great-Grandchild"
set theNewFolder to "Folder_First_Great_Grandchild"

if FolderExists(theFolder) = true then

    --display dialog "Exists " & theFolder & " !"
    --delete the file
else

    --display dialog "Missing " & theFolder & " !"
    -- do nothing or something else
end if

--handler for checking if exists theFolder/thePath

on FolderExists(theFolder) -- (String) as Boolean
    tell application "System Events"
        if exists folder theFolder then
            return true
        else
            return false
        end if
    end tell
end FolderExists

This is all I found for now.

Best regards

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