Compress files with the output name same as Parent Folder with Automator

applescriptautomatorbash

I've been searching the internet for a solution to this. I would like to create an Automator workflow that will zip the selected files, name the zip the name of the Parent directory and save that zip in the current directory.

I can't seem to find a way to get the parent directory. I've kinda hit a wall here. Could anyone help me out?

Best Answer

In Automator:

  1. Add Get Selected Finder Items
  2. Add Run Applescript

Inssert this code for the Applescript:

on run {input, parameters}
 set pathList to {}
 repeat with itemNum from 1 to count of input
 tell application "System Events"
 copy POSIX path of (container of (item itemNum of input)) to end of pathList
 end tell
 end repeat
 return pathList
end run

Output/Results:

2013-05-11 00:06:02 +0000: Get Selected Finder Items completed
2013-05-11 00:06:02 +0000: Conversion from Files/Folders to Files/Folders completed
2013-05-11 00:06:02 +0000: Run AppleScript completed
2013-05-11 00:06:02 +0000: Workflow completed

{"/Users/Desktop", "/Users/Desktop", "/Users/Desktop"}