bk161124 Posted February 24, 2017 Share Posted February 24, 2017 (edited) Hi! I’ve been trying to build a zip Workflow because those existing don’t work for me and I thought this might be a good exercise. Unforntunately I ran into a problem: My zip Workflow works fine for folders (they get zipped and the zipfile is created in the same folder) but when I zip multiple or just one file the archive is created in the Workflow Folder in /Library/Application Support/ I can’t find why that is. For Folders I’m using a file action that does not accept multiple files and accepts only folders. I call a bash Script: query=$1 zip -jr {query}.zip {query} echo -n $query For files the file action accepts multiple files and is set to +public.content. The bash script is nearly the same query=$1 zip -jrv Archive.zip {query} echo -n $query I guess in the {query} object the path is given? How could I alter the code to write in the right directory? I can’t name the archive {query} because than the filename would be the name of all passed on files, right? Thanks for your help! Edited February 24, 2017 by vitor Removed exclamation from title Link to comment
vitor Posted February 24, 2017 Share Posted February 24, 2017 You code does not make sense. query=$1 is redundant, and you may be confusing yourself since you’re using both {query} and $query. It’s either one or the other. Alfred will either understand $1 or {query} — not both — depending on what you tell it to in the with input as dropdown. The reason it’s creating the zip file in the workflow’s directory is that’s where you’re in. The script runs in the workflow’s directory. That means you need to either give your commands a path to act on, or change to another directory. Assume that when you start a Run Script, you cded to the workflow’s directory. As for a workflow for zipping that works, try this one: deanishe 1 Link to comment
deanishe Posted February 24, 2017 Share Posted February 24, 2017 To add to what Vítor said, you should also quote your variables in commands (i.e. zip -jrv Archive.zip "$query", not just zip -jrv Archive.zip $query) or your script won't work if a filepath has a space in it. Link to comment
bk161124 Posted February 25, 2017 Author Share Posted February 25, 2017 12 hours ago, vitor said: As for a workflow for zipping that works, try this one: Thanks for your answers! The Workflow by Carlos-Sz does not for for zipping folders for me unfortunately, if it did I hadn’t bothered building my own simple version. I’ll try and figure out how to change the directory according to the query input! 10 hours ago, deanishe said: To add to what Vítor said, you should also quote your variables in commands (i.e. zip -jrv Archive.zip "$query", not just zip -jrv Archive.zip $query) or your script won't work if a filepath has a space in it. Added this! Link to comment
vitor Posted February 25, 2017 Share Posted February 25, 2017 2 hours ago, bk161124 said: The Workflow by Carlos-Sz does not for for zipping folders for me unfortunately Mind making a small video of the problem? You can record your screen with QuickTime Player. Also, open the debugger, and post the output when it fails. Why haven’t you opened a bug report in one of the existing issues, though? It’d be quicker than trying to roll your own workflow and it’d fragment options less. Link to comment
bk161124 Posted February 26, 2017 Author Share Posted February 26, 2017 22 hours ago, vitor said: Mind making a small video of the problem? You can record your screen with QuickTime Player. Also, open the debugger, and post the output when it fails. Why haven’t you opened a bug report in one of the existing issues, though? It’d be quicker than trying to roll your own workflow and it’d fragment options less. I think that a video wouldn’t help as simply nothing happens. The debugger states: Quote Starting debug for 'Zip' [2017-02-26 11:56:12][ERROR: action.script] 2017-02-26 11:56:12.827 osascript[6454:2396048] ApplePersistence=NO 0:76: execution error: Can’t make text items 1 thru -2 of "Testfolder" into type text. (-1700) I’m guessing that’s because I rely on PathFinder? I haven’t filed a bug report because I thought it would be a good starting point for getting to know Alfred Workflows better and because I can add my own small enhancements now that you helped me figure out how to do it. Link to comment
steyep Posted March 9, 2017 Share Posted March 9, 2017 The first issue, that's already been discussed, is the fact that you're outputting the Archive.zip file into the directory that's executing the script. You can prepend the output file name with a directory and you should be good to go. If you're intending to output the zip file into the directory of the file you're compressing, you can access that with dirname. The second issue is that multiple files are passed to the script with a tab delimiter – meaning there will be more than one argument passed to your script so zipping {query} or $1 will only zip the first file. Here's what I would suggest: zip -jrv "$(dirname "$1")/Archive.zip" "$@" Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now