automator question

i figured out how to setup automator workflows and an app (with all the workflows in it) that can backup and zip a specific set of folders on my mac and put them in specific locations.


automator allows me to create an archive - but using the macOS built-in archive utility only.


i like to use keka instead for creating password protected 7z archives of files/folders ... and i found the command that i need (compress using keka) has its own keyboard shortcut assigned (in system preferences/keyboard/shortcuts).


i want to create a workflow where i do this:


1-get specified finder items

2-copy finder items (to another folder)

3-invoke the keyboard shortcut on the folder i just copied, to compress using keka.


i keep keka open, with the settings and password i want to use and when i manually do a ‘compress using keka’ on a folder, it creates the archive and deletes the source folder when its done.


i am doing this manually for 3 or 4 folders of interest on my mac, and automator helps simplify but i cannot figure out how to get it to use keka instead of archive utility.


if i can do this another way, like create a script and turn it into an app, that also works. im not necessarily married to Automator.


grateful for any help to accomplish this ...

MacBook Pro 15", macOS 10.15

Posted on Feb 19, 2020 8:06 AM

Reply
25 replies

Feb 19, 2020 10:54 AM in response to zero7404

Automator by design takes the result of each action and passes it on to the next one.


In the example, the specified folders and files in the first action would be copied to the "Stuff" folder; this would be passed on the third action as an input (which in this case is not actually used).


The "System Events" application is what we use to generate keystrokes in Applescript. These type of things is what one sometimes refers to as "GUI scripting", as you are basically scripting your interaction with your mac (by simulating a key press, in this case).


A keystroke will act on whichever application is active (frontmost). We want the Finder to receive command-shift-K.

The first tell command makes Finder the frontmost application (so that the next keystrokes act on the Finder):


tell application "Finder"

activate

end tell


then the second tell command generates the actual keystroke

(command-shift-K in this example).

These lines generate the keypress:


tell application "System Events"

keystroke "k" using {command down,shift down}

end tell


It is easy to see how to adapt this to send, say, command-option-w to Preview, or whatever. It is always the same: activate the desired application, then tell "System Events" to enter a keystroke.

Feb 19, 2020 9:34 AM in response to zero7404

If anything has a keyboard shortcut, then it is easy to automate.

If I understand correctly, you have a shortcut that given a selected folder in the Finder, executes the "compress using keka" on that folder.

For the sake of this example let us suppose the shortcut is Command-Shift-K


You can use a little AppleScript action to programatically "press" the appropriate shortcut. It will be something like this:



Feb 19, 2020 11:03 AM in response to Luis Sequeira1

on the second tell command, is it assumed that finder is actually selecting/highlighting the folder which i want to perform the shortcut on ? for instance, what if there were additional files/folders inside the working folder that this is all happening in ?


i’ll try to post a screenshot later on, of the workflow before i save and make it part of an executable.

Feb 19, 2020 5:44 PM in response to Luis Sequeira1

this is what i have in automator, using apple's archive utility:



before trying to change this workflow .... i tried the keyboard shortcut on a file to see if it works, but it appears to do nothing. i made sure keka is running and ready.


the shortcut is: control+shift+C

in Preferences/Keyboard/Shortcuts it is located within Services and under Files and Folders

it is checked, as if it is activated/enabled:




not sure why the keyboard shortcut is not working .... so i won't change the workflows just yet.


Feb 20, 2020 5:14 AM in response to Luis Sequeira1

interesting ....


ill give it a shot and see .... if it works then ill update the workflows.


i should also create a workflow to startup keka for me before proceeding to archive ... since i manually do that now.


only thing with keka is that if i start a new instance of it i have to type in the encryption password i want to use, in 2 fields (specify the password, confirm the password).


maybe i can ask the developer if thats a functionality that can be made to stick.

Feb 23, 2020 8:50 PM in response to Luis Sequeira1

i tried the suggestion, and it looks like every step is working, except the applescript step.


counting from the top (1-get specified items, 2-copy, 3-get specified items, 4-applescript, 5-rename) .... it performs steps 1, 2, 3, 5. not step 4.


i tried to test the keyboard shortcut manually in finder on the folder, and keka compresses it.


just for the record, keka does not need to be running when the shortcut is invoked. keka compresses whatever i have highlighted in finder. i asked (above) whether the folder in the workflow step needs to be highlighted/selected explicitly before it can be passed to the applescript step.


i had to take 2 screenshots (below) to show you the entire workflow and step 4 appears in both.





Feb 25, 2020 7:38 AM in response to Luis Sequeira1

if i create a script outside of automator and record my actions, it generates the script text of what i am doing in finder.


i can use the folder path in that script to specify the set target.


but how would i integrate that statement into a script that ultimately takes the target folder, and performs the keka shortcut on it ?


i have keka set to delete the folder it is archiving, so when the script is done, the only thing left should be the 7z file.


that is where i am getting stuck, maybe i should make the script its own workflow or service in automator .... ? and then use it in an automator app ....


right now i have these workflows inside a single app:


first - this clears out the old archive file from the destination folder:

find finder item -> send it to trash


second - create the archive in the destination:

get specified finder items -> create archive (in the destination folder) -> rename the archive


if i use keka instead of archive utility, i’d probably modify the 2nd to:

copy finder items -> run the script on the finder item in the destination folder (keka will delete the folder after it archives it) -> get specified finder items (to fetch the new archive file) -> rename the archive.


not sure if thats the correct order or way to do it.

Feb 25, 2020 3:38 PM in response to Luis Sequeira1

somewhat vague ....


if i have a series of workflows inside of an app, where each workflow is compressing a folder, would the workflow that follows it be taking the compressed file of the previous and including it in its own compression task ?


i have noticed inconsistent zip file sizes for instance a 144mb folder is compressed to 1.3gb. that is strange when looking at another folder thats 2.5gb being compressed to 1.2 gb.


i may be doing the automation wrong

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

automator question

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.