开发者

How to create a folder on desktop and move the dropped file in it with AppleScript?

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 w开发者_如何学Goas 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. :)


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).


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜