Jump to content

[SOLVED] How to split arg from list filter to use in run script


Recommended Posts

I would like to split a comma separated arg value from a List Filter which can then be used in Run Script as variables.

 

arg = 1p name of bookmark1, 1p name of bookmark 2, name of bookmark 1, name of bookmark 2

 

I know of the Split Arg to Vars utility and can split these into 4 strings, ex: var:string1, var:string2, var:string3, and var:string4...

but I can't get these to be used as variables within the Run Script itself. My Run Scripts are not throwing errors, but the strings are empty when I attempt to use them.


I understand it is likely hard to solve this without a concrete Workflow.  There are many more parts to what I'm building and this is the main part that is stumping me.
I've actually solved this problem in a non optimized way using a Conditional.  I would like to avoid code duplication and also solve how to use variables in my scripts in general.


Other research:

  • I've found "AppleScript Two Words" thread, and that's close, but my strings are not single words as shown above. I'm also using a List Filter rather than query
  • I'm aware of setting variables via Arg and Vars
  • I've also read https://www.deanishe.net/post/2018/10/workflow/environment-variables-in-alfred/.  I can apply: 
    • Applescript set theBrowser to (system attribute "browser") type command into my script
    • ... but like I said above it will produce empty strings within my script.
  • I've been using the Debugger to view the variables created.  It seems like at the script level they are not available yet I'm able to set them somehow?

 

Note: This is part of a larger workflow where I'm actually passing these strings to 1Password as "1p name of bookmark".  The reason I want to strip "1p" from the bookmark names is that I am going to re-use those names to launch 1Password application and display the bookmark within the app (ex: keystroke from Applescript or copy/paste)

Any help or pointers is greatly appreciated.  I am also more than happy to use other scripting languages which can control external apps.  I'm familiar with Python, Ruby, Javascript, Shell.
 

Link to comment
5 hours ago, douggtg said:

I understand it is likely hard to solve this without a concrete Workflow. 

 

This. Without a workflow, you're basically just asking us to guess at what might be wrong.

 

If you can't or won't share the workflow with the problem, can you create a separate workflow that demonstrates the problem you're having and post a link to that?

Edited by deanishe
speling
Link to comment

Yeah, I suspected this might be the problem, seeing as your description of how to use variables was fairly spot-on.

 

6 hours ago, douggtg said:

I can't get these to be used as variables within the Run Script itself

 

You aren't using a "Run Script" action, you're using a "Run NSAppleScript" one. They're completely different things. "Run NSAppleScript" executes your script in a thread in Alfred itself, not as an external process, which means that Alfred (i.e. environment) variables won't work. If you use an actual "Run Script" action (with Language = /usr/bin/osascript (AS)), it works as expected.

 

As a rule, you should never use "Run NSAppleScript" unless you have a good reason to do so (and I don't know of one).

 

Also, there's no need to simulate keystrokes to enter text in Alfred. You can  use its AppleScript API: tell application id "com.runningwithcrayons.Alfred" to search "your text".

 

What exactly are you trying to achieve?

Edited by deanishe
Link to comment
20 minutes ago, douggtg said:

I am then passing these to 1Password using "1p" integration via Alfred.

 

Wouldn't it make more sense to trigger the 1Password extension in the browser rather than using Alfred's 1Password integration?

 

In any case, did replacing your "Run NSAppleScript" actions with normal "Run Script" ones work?

Edited by deanishe
Link to comment

@deanishe

 

Quote

You aren't using a "Run Script" action, you're using a "Run NSAppleScript" one. They're completely different things. "Run NSAppleScript" executes your script in a thread in Alfred itself, not as an external process, which means that Alfred (i.e. environment) variables won't work. If you use an actual "Run Script" action (with Language = /usr/bin/osascript (AS)), it works as expected.

 

As a rule, you should never use "Run NSAppleScript" unless you have a good reason to do so (and I don't know of one).

 

Also, there's no need to simulate keystrokes to enter text in Alfred. You can  use its AppleScript API: tell application id "com.runningwithcrayons.Alfred" to search "your text".


I somehow missed this earlier reply... Will try work on this more.  Sorry, getting used to this forum

 

Edited by douggtg
Link to comment
  • vitor changed the title to [SOLVED] How to split arg from list filter to use in run script

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...