More snippets from my adventures with @AlfredApp and AppleScript. For this one, I needed to fulfill a couple of requirements, similar in nature to my previous e-mail code:
- Most importantly I needed to figure out a way to utilize a single string entry into Alfred that could be interpreted with multiple variables. Example: Triggering alfred and typing trigger Severity-Subject-Context producing three distinct variables within an AppleScript:
- Severity
- Subject
- Context
The hardest part about all of this is dealing with Alfred’s input scheme. As far as I can tell (and even using @preppeller’s own Tumblr) it seems that there’s no easy way to differentiate a single Alfred string to multiple variables. In that Tumblr piece, Preppeller shows off the following code snippet:
on alfred_script(q)
tell application "Things"
parse quicksilver input q
end tell
end alfred_script
This would be great if it weren’t for the fact that instead of Alfred handling the variables of the input, he’s turning to @CulturedCode’s Things App and its ability to parse out syntax provided. In my situation unfortunately, @SparrowApp doesn’t have that ability and it’s what I needed (I blame neither party!). Another good example actually got to me from the team itself while writing this blog, take a look for how he handled it using a shell script.
So putting around, I decided I was going to use AppleScripts “do shell script” to parse out the line using sed and a relatively complex regex. I’m sure I could do this much, much better some other way, but this is how I did it! I figured that since it took me a bit of time, I could help others by providing my tools. I’m not going to link anything for a bit, but please see links at the bottom of the post for some of the tools and resources I tapped into. More after the break. Continue reading