fncll Posted June 29, 2021 Share Posted June 29, 2021 I am trying to create a workflow that work with two arguments. I am calling an external script (using the "run script" action; see screenshot) with the code below. It works fine from the command line but appears to pass no arguments to the script in Alfred..the workflow completes but nothing is added to the file. What am I doing wrong? #!/usr/local/bin/bash SCALE=$1 DESCRIPTION=$2 UPDATE="" CURRENTDATE=`date +"%Y_%m_%d"` CURRENTTIME=`date +"%H:%M"` UPDATE+="$CURRENTTIME [[🧠]] [[" for (( i = 1; i <= SCALE; ++i )); do UPDATE+="🔷" done UPDATE+="]] $DESCRIPTION" printf "\n- $UPDATE" >> "/Users/chris/Library/Mobile Documents/iCloud~md~obsidian/Documents/bujo/journals/${CURRENTDATE}.md" Link to comment
vitor Posted June 29, 2021 Share Posted June 29, 2021 External Script doesn’t take arguments, which is why with input as argv is greyed out. Use /bin/zsh instead and call your script from the box: ./test.sh "${1}". However you’re going into that Run Script, you’re probably passing it one argument, not two—Alfred isn’t a shell, it won’t split what you give it on spaces—you need to take that into account. In the future, when asking for help with a Workflow please upload it somewhere as it’s hard to help you without access to it. Debugging can already be hard with access to the code, and you’re asking us to guess yours from a description. There are multiple places where your code or Workflow setup may be going wrong. See the Reporting Problems with Workflows topic for a nice overview on how to build an effective report. Link to comment
fncll Posted June 29, 2021 Author Share Posted June 29, 2021 My apologies. The code I posted IS the workflow, but for the Keyword action that leads into it with argument required. I assumed the greyed out arguments area in my screenshot was because it didn't have an option to choose between argument types, not that it takes no arguments at all. Based on information here, I'd already tried your approach (using bash, not zsh), and have now tried using zsh as you suggest with the same (lack of) result. I've shared the workflow, using zsh here: https://www.dropbox.com/s/mbcpkzfp2vwqq7z/mood.alfredworkflow?dl=0 I'm running Alfred 4.3.4 on OSX 11.4 with no system changes. As noted, test.sh works fine from the command line. Link to comment
giovanni Posted June 29, 2021 Share Posted June 29, 2021 add bash? bash test.sh "${1}" works for me (I get an error from the script though) Link to comment
vitor Posted June 30, 2021 Share Posted June 30, 2021 1 hour ago, giovanni said: add bash? That starts another shell, which is unnecessary. 1 hour ago, fncll said: and have now tried using zsh as you suggest with the same (lack of) result. But you still haven’t split the arguments. Your script wants two and you’re only giving it one. Look into the Split Argument to Variables Utility. Link to comment
fncll Posted June 30, 2021 Author Share Posted June 30, 2021 Ah, I see. Ok, looks like Alfred won’t be the tool for me. Thanks for your help. Link to comment
Andrew Posted June 30, 2021 Share Posted June 30, 2021 10 hours ago, vitor said: External Script doesn’t take arguments, which is why with input as argv is greyed out. This isn't actually true, when you select External Script, arguments are passed as argv (it says that in description under the script file). 8 hours ago, fncll said: I assumed the greyed out arguments area in my screenshot was because it didn't have an option to choose between argument types, not that it takes no arguments at all. That is the correct assumption, for example, this script would echo back the arg: The External Script option is my preferred option as it allows you to use any scripting language, and your external development environment. Cheers, Andrew Link to comment
vitor Posted June 30, 2021 Share Posted June 30, 2021 (edited) On 6/30/2021 at 8:42 AM, Andrew said: This isn't actually true, when you select External Script, arguments are passed as argv (it says that in description under the script file). I stand corrected! Has that always been the behaviour? Unsure why I thought it wasn’t. @fncll Here’s your Workflow fixed. Note how there are almost no changes. The link I posted earlier should explain it, but ask if you have a question. I purposefully made no changes to your script other than the arguments, but you should consider changing /Users/chris to ${HOME} so it’s not tied to your specific username/machine. Edited July 1, 2021 by vitor Link to comment
deanishe Posted June 30, 2021 Share Posted June 30, 2021 @fncll: It looks like you want to use a Run Script with bash or zsh (depending on which you prefer) with input via {query} and all escaping options turned off. That will insert your input into the script as if you'd typed it and the weird shell parsing semantics you want will be applied. Link to comment
Andrew Posted June 30, 2021 Share Posted June 30, 2021 4 hours ago, vitor said: I stand corrected! Has that always been the behaviour? Unsure why I thought it wasn’t. Yep, it's been like that since the day I added in External Scripts vitor 1 Link to comment
fncll Posted July 1, 2021 Author Share Posted July 1, 2021 Thanks, @vitor, but your workflow exhibits the same issue. If I run the test.sh script embedded from the workflow from the command line like this: ./test.sh 5 "foo bar" Then the result is written to the file as intended, like this: 19:52 [[🧠]] [[🔷🔷🔷🔷🔷]] foo bar The issue is that when I use the same input in Alfred: m 5 "foo bar" using your revised workflow (or my original), this is written: 19:53 [[🧠]] [[]] Sorry if I'm being obtuse. I'm (obviously) not a programmer! Link to comment
vitor Posted July 1, 2021 Share Posted July 1, 2021 8 hours ago, fncll said: your workflow exhibits the same issue. My mistake on the upload, I uploaded your version! I’ve updated the link with the correct Workflow. Note that it no longer requires quotes, you should just m 5 foo bar or ./test 5 foo bar and it will divide it into the first argument (SCALE) and everything else (DESCRIPTION). giovanni 1 Link to comment
fncll Posted July 1, 2021 Author Share Posted July 1, 2021 Thank you, thank you! The proverbial penny has dropped and now I understand what is going on. I very much appreciate your help (and patience). vitor 1 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