This is very easy to do using the File Actions action (KM Wiki).
Assuming that you have the POSIX path from Step #1, you can just use that in the Move File action.
3. Zip Folder
I recommend using the Bash ditto command since it will produce the same results as the Finder "compress" command, thus retaining all of the resources and extended attributes of the files.
Here is an example macro, which you will need to adapt for your use.
MACRO: Zip (Compress) Folder Using Ditto [Example]
Hi!
Just tried adapting your macro a little bit but I'm getting ditto: can't get real path for source error.
Here is my setup:
I'm watching a folder for adds an item
Then set the file name
Set Variable “ZIP_ArchiveName” to Text
%TriggerValue%.zip
And then use the ditto command in the Execute Shell Script action ditto -ck --keepParent "$KMVAR_TriggerValue" "$KMVAR_ZIP_ArchiveName"
It looks like it's ditto's error, but I'm not sure how to troubleshoot it. Any help would be appreciated!
=== EDIT ===
Well, actually I'm not sure. I just tried it with tar tar -czf "$KMVAR_ZIP_ArchiveName" "$KMVAR_TriggerValue"
And it gives me Cannot stat: No such file or directory error
So I guess I'm doing something wrong.
I don't see where you defined a KM Variable "TriggerValue".
If you intended for that to be the KM token %TriggerValue%, then you need to set a KM Variable, SourceFilePath, to %TriggerValue%.
Then your ditto command would be: ditto -ck --keepParent "$KMVAR_SourceFilePath" "$KMVAR_ZIP_ArchiveName"
Aaah! I thought the token %TriggerValue% can be used as a variable.
Now when I set as
* Set Variable “OriginalFile” to Text
* %TriggerValue%
everything works.
Oh, btw another quick question if you don't mind?
If I want to delete the original file once it's been archived with:
* Delete File “%TriggerValue%”
* Notify on failure.
do I need to set some kind of delay, to make sure the file does not get deleted before it is archived?
Or KM would not proceed from the archive shell script action unit it is done (shell returns 0)?
I'm not a shell script expert, but I believe that KM would not move from the shell script Action until the script had completed.
This is probably OK, but I prefer to set a KM variable to the token at the top of the Macro, and then just use that Variable throughout the Macro. If you use a descriptive name like "SourceFilePath" then it is clear everywhere in the Macro what you are referring to.
This is probably OK, but I prefer to set a KM variable to the token at the top of the Macro, and then just use that Variable throughout the Macro. If you use a descriptive name like "SourceFilePath" then it is clear everywhere in the Macro what you are referring to.
Absolutely agree. I'm pretty paranoid about naming my vars/functions/classes in code, so I've been wanting to read up on KM variables, and organize them somehow in some kind of hierarchy (groupName_macroName_varName or something) because right now my KM vars are a complete mess, lol.