Jump to content

performing a regex in a 'run nsapplescript' workflow action


Recommended Posts

Hi there!

 

I have a workflow which will open a new chrome browser to our jira server for a particular ticket:

 

it fires off a keyword with an argument, and goes to a 'run NSAppleScript' action:

---

on alfred_script(q)
 
    set theText to "https://my.jira.fqdn/browse/" & q
tell application "Google Chrome"
    tell (make new window)
        set URL of active tab to theText
    end tell
    activate
end tell
end alfred_script
---
 
what I want to do is give myself the ability to not type the FULL ticket number, for tickets inside the project I work on the most. Most of the tickets I have look like this:
 
FOOBAR-1234
 
some string of text, a hyphen, and a set of digits.
 
I'd like to extend my current workflow such that I can either enter "SOMEPROJECT-1234" which would turn the url into "https://my.jira.fqdn/browse/SOMEPROJECT-1234"
 
OR
 
I could enter '1234' which would turn the url into
 
How might I do this most efficiently?
 
Thanks so much in advance for your help!
Link to comment

formatting here is a little weird but this code should work.  Regex is overkill for this task, I think:


 


 


property lower_alphabet : "abcdefghijklmnopqrstuvwxyz"


property upper_alphabet : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"


 


set c to the first character of q


 


if c is in lower_alphabet or c is in upper_alphabet then


set theText to "https://my.jira.fqdn/browse/" & q


else


set theText to "https://my.jira.fqdn/browse/FOOBAR-" & q


end if


Edited by dfay
Link to comment

that didn't end up working, actually.

 

For future people looking, this is how I ended up getting it working:

on alfred_script(q)
  if q contains "-" then
    set theText to "https://my.jira.fqdn/browse/" & q
  else
    set theText to "https://my.jira.fqdn/browse/FOOBAR-" & q
  end if
  tell application "Google Chrome"
    tell (make new window)
      set URL of active tab to theText
    end tell
    activate
  end tell
end alfred_script

since every ticket contains a project, a hyphen, and a ticketnumber, I can just see if the string has a hyphen. Crude, but generally functional.

Edited by Wolfspyre
Link to comment

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...