Jump to content

[SOLVED] Could not get the user given argument at last part of workflow


Recommended Posts

I am learning how to use the Alfred to make some interesting workflows. 

I was modifying a workflow so that it takes a user argument, and passes that variable to the last part of the workflow.

 

Alfred command:  trim 25

Last part of Alfred gives: the youtube link

How can we get the user given argument : eg. 25

 

Required output in ~/Downloads/hello.txt:

25
https://www.youtube.com/watch?v=kJQP7kiw5Fk

 

The link of the workflow is shared in github alfred two arguments .

 

 

Its a noob question, but, I would appreciate your help. Thanks.

Edited by Bhishan
Link to post

Welcome.

 

We can’t properly help you without access to your Workflow.


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. Without looking at it we’re shooting in the dark, which is a waste of time for everyone involved (including you).


Read the Reporting Problems with Workflows topic, as it gives a nice overview on how to build an effective report.

Link to post

I don’t see the piece of code you mention in your first post anywhere in the Workflow.


Two preliminary notes:

  1. You have a lot of cruft inside the Workflow’s directory, including a stray .mp3.
  2. There’s no point to zipping an Alfred Workflow. They’re already zipped directories with a changed extension.

Link to post

@vitor My bad, that was just an example case how I want to use the variable, I have no problem with that code, I just need to get the value of the argument.

 

For example, 

How can we write following things in the text file '~/Downloads/hello.txt' ?

 

25
https://www.youtube.com/watch?v=kJQP7kiw5Fk

I have updated both the question here and the workflow in GitHub.

 

My apologies for unnecessary complications.

Edited by Bhishan
Link to post

The problem is that you're trying to store two values in one variable. When your first Keyword element finishes, {query} = 25. Your Run NSAppleScript element immediately overwrites this with the YouTube URL, so {query} = https://www.youtube.com/…


You need to insert an Args and Vars Utility after the trim Keyword to save the user input to a different variable.


Here is a working version with the above changes.

Link to post

@deanishe   @vitor  Thanks folks, now I can get two variable but again have the shell escaping problem.

The workflow does not work still.

 

The updated workflow with youtube-dl and ffmpeg commands is uploaded in github link .

 

In bash script it can be done in very few lines:

# initial x seconds trimmed mp3 song
# mytrim 36 https://youtu.be/f1qz8vn3XbY?list=RDYuXLN23ZGQo&t=219
mytrim() {
    local downloaded_file
    /opt/local/bin/youtube-dl --extract-audio --embed-thumbnail --audio-format mp3 -o "%(title)s.%(ext)s" $2
    downloaded_file=$(/opt/local/bin/youtube-dl --get-filename --extract-audio --embed-thumbnail --audio-format mp3 -o "%(title)s.%(ext)s" $2)
    /opt/local/bin/ffmpeg -ss $1 -i "${downloaded_file}" -acodec copy -y temp.mp3
    mv temp.mp3 "${downloaded_file}"
}

 

Edited by Bhishan
Link to post

@deanishe @vitor

 

Getting aside from the actual youtube-dl command, the command needed is this:

cd ~/Google\ Drive/Music/Downloaded

touch "this file had space and @ # etc.webm"

filename=$(ls *.webm) 



echo $filename >> output.txt   # This works good

touch $filename # This fails, creates multiple files for each space-separated name of the input file

 

How can we get a shell escaped variable in Alfred by reading the filename in bash?

 

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...