Close the folder using apple script

I am trying to use applescript to copy a folder to my desktop, zip, and then move the .zip file to another location, but I cannot get the zipping part to work.

I have searched everywhere for ways to pin a file / folder into applescript, and I don't know what I'm doing wrong, but none of them worked for me.

I also would not need to select a folder after copying it and a folder after zipping it, but I thought that I would leave them until it was fixed.

Any help at all would be appreciated.

This is my code: (updated after djbazziewazzie help)

set workspace to (path to desktop as text) --"Users:produser:Desktop"

tell application "Finder"

display dialog "Select a folder to be zipped"
set inputFolder to choose folder
set inputFolderProperties to properties of inputFolder
set inputFolderName to name of inputFolder

duplicate inputFolder to workspace with properties --copy input folder to workspace
{name:inputFolderName} --keep the same name

--set copiedFile to (workspace & inputFolderName) 
display dialog "Select the folders desktop copy"
set copiedFile to choose folder --select the file copy thats on the workspace

tell current application
    set qpp to quoted form of POSIX path of copiedFile
    do shell script "zip -r " & qpp & ".zip " & qpp -- zips the file (or not...)
end tell

display dialog "Select the .zip file" --select the new .zip file
set zipFile to choose file
display dialog "Select the output folder"
set outputFolder to choose folder --moves zipped file
move zipFile to outputFolder

end tell   
+4
source share
1 answer

- , -r zip, zip . Mac OS X, .app, , .

do script - "Finder" . do shell script , ​​ current application. , ,

tell current application
 do shell script "zip -r " & qpp & ".zip " & qpp -- zips the file (or not...)
end tell

1:,

EDIT 2: ​​ do script

set workspace to (path to desktop as text)

tell application "Finder"
    set inputFolder to choose folder with prompt "Select a folder to be zipped"

    set copiedFile to (duplicate inputFolder to workspace) as string
    set copiedFile to text 1 thru -2 of copiedFile --remove the trailing ":" 

    tell current application
        set qpp to quoted form of POSIX path of copiedFile
        do shell script "cd $(dirname " & qpp & ")
    zip -r  \"$(basename " & qpp & ").zip\" \"$(basename " & qpp & ")\""
        set zipFile to copiedFile & ".zip"
    end tell

    set outputFolder to choose folder with prompt "Select the output folder"
    move zipFile to outputFolder
end tell
+2

Source: https://habr.com/ru/post/1538737/


All Articles