On a Mac: Can I create a key shortcut to run a bash code based on clipboard content - bash

It has been a while since I coded a little bit and I only use Mac for a couple of weeks.
Here is what I would like to do:
I have a spreadsheet with email addresses, subjects and text bodies for an email.
I can summarize this data in a way that I have a cell that is filled with
to=foo#nowhere.net,subject='test subject',body='test body'
Now, I would like to copy this line to clipboard and create a keyboard shortcut to run this code
cd /Applications/Thunderbird.app/Contents/MacOS/
./thunderbird -compose "CLIPBOARD CONTENT"
I would like to use this to automatically create an email based on the (dynamic) content of the spreadsheet.
Is this possible or does anyone have a better idea how to create such emails? I have tried to work with mailto-links but it does not work because there is some more complexity to the spreadsheet which makes it impossible.
Thank you!

This workflow works from within Automator (even though I feel it's kind of buggy). Unfortunately, when I call it using a shortcut from within other apps it throws an error:

Found the cause of my error 212:
The of front workflow statement does not work from outside Automator because then, it is not the front workflow anymore. I had to do a workaround that does not use this statement...

Related

Adding environment variable to a commandline argument in a windows shortcut

So I'm trying to make a mailto link on a windows desktop. This is to automate opening a mail client by inserting the recipient and subject automatically. I can do just that, however I'd like to include either the current date or the previous date in the beginning of the subject line. I've tried:
%windir%\explorer.exe mailto://user#email.com?subject=%date% 'Rest Of Subject'
and every other variant I can think of. The link either reads %windir% correctly or just skips it but opens fine. However, I see the literal '%date' in my subject.
Is this possible without using batch files or scripting? This is for work different computers at different locations, where users aren't exactly computer savvy and need things done for them. Also for bonus points, is there a way the also make the file attach dialog pop up? The purpose of this is to send security log word document from different locations to a central email address. Thanks and I hope to hear from anyone who can direct me where to look or give me some hints on my command line fu!

Open an application in a space using applescripts

I am trying to create a script that will open an application in a specific "space". So let's say I am on space 1 working in the terminal and then I want to be able to open safari in space 4. Is there a way to do this?
I have done some searching and found only ways to set the system profile options. Maybe I should tell you my end goal in case what I am attempting is not possible.
I use a laptop and plugin in to multiple stations, home, office, and travel. I want to create different window layouts for each one. So I will need an apple script telling it to open applications in varios spaces and different dimensions. I hope this makes sense. Ask me for clarification if it doesn't thanks!
PS the answer doesn't necessarily have to be any applescript I just thought that would be the easiest way :)
Here's a list of applescript commands for Spaces. There's a couple things there that might help you.
It is possible to do some scripting of application Space preferences by using the scripting interface to the System Events.app. See the answer to a similar question here.
The easiest way I've found is via GUI scripting. Make sure the Spaces menu is active on the upper right of your computer. That lists the spaces by number. You can then just write a GUI script to select the menu item of the space you wish. That will switch to that space. Then do an activate Applescript to open the application there.
Let me know if you need sample code demonstrating this. I have some in Python + Appsscript that does this but I should be easily able to convert it back to Applescript proper if you need it.

Copy current selection on hotkey

I want to copy the current selection, even if it's in another application like Mail, when the user hits a specified hotkey like Cultured Code does it in Things when you create a new task. I got the hotkey working and I know how to place and get stuff on and from the pasteboard. But I have no idea how to get a current selection.
Anyone? Thanks!
You do this with a Service Provider. See the Service Implementation Guide. For what you're talking about, it should work very well. You don't need to do your own hotkey code; it'll do that for you. You don't even have to be running; it'll launch you.
To #Josh Caswell's point about OmniFocus, they're doing stuff fancier than just "the current selected text." They also copy the message itself into the inbox item as an attachment. That's what the plugin is assisting with.
This is a job for AppleScript, which is why applications that do clipping like this only support certain other applications to clip from -- those other applications have to support AS.
You'll have to take a look at the Mail AS dictionary and figure out how to get the selected text, and I believe that unfortunately you'll have to do the same with each application from which you want to clip.
Another possibility: it sounds like OmniFocus uses a Mail plugin for this functionality -- from http://forums.omnigroup.com/showthread.php?t=13906:
Starting in 10.6, Mail.app will refuse to use plugins... install the Clip-o-tron from that updated release... "OmniMailMessageEnabler...".

AppleScript Editor record doesn't work

I have opened the AppleScript Editor and pressed Record button.
Then I run TextEdit, create a file and put some text there.
When I click the Stop button in AppleScript Editor, nothing was recorded, the window is blank.
What is the problem?
You can use the Record feature of the Automator to record the UI interaction steps needed to do the relevant workflow. Then you can then literally select and copy the recorded steps in automator and paste them into a new Applescript Editor window. This will give you applescript which may or may not work. You'll probably want/need to edit the resulting script, but at least it should help give an idea what is needed to achieve your workflow programatically. This method is usable regardless of whether or not the target application has an applescript dictionary or supports the AppleScript Editor Record button, as it is the interaction with the underlying UI elements which is recorded.
Steps:
Open Automator
Start a new "Workflow"
Start recording
Perform whatever steps you require with your app (in this case typing into textedit)
Stop recording
This will create a list of actions in Automator like:
Select all these and copy (CMD+c)
Open the Applescript Editor app
Paste (CMD+v). The result will be valid applescript to perform the actions you just recorded:
Note that as is generally the case with UI automation, the automator records steps exactly and the script plays them back exactly. This my not be exactly what you want - e.g. if a different application were active, the text could get typed in there instead. The generated applescript should be used as a guide to the final applescript.
The problem is that applications need to explicitly support AppleScript recording in order for it to work, but almost no applications actually do. Finder still supports it a bit, and maybe a couple other apps (BBEdit comes to mind), but for the most part, AppleScript recording has been pretty useless for quite some time.
Not all apps are recordable (in fact, only a small handful are). Recordablity is something each app needs to implement, and I guess TextEdit isn't recordable.

Creating quick GUI front ends

I wanted to have a GUI front-end for a script that accepts numerous command-line options, most of them are UNIX paths. So I thought rather than typing them in (even with auto-completion) every time, I'd create a GUI front end which contains text boxes with buttons beside them, which when clicked will invoke the file browser dialogue. Later, I thought I'd extend this to other scripts which would sure require a different set of GUI elements. This made me think if there's any existing app that would let me create a GUI dialog, after parsing some kind of description of the items that I want that window should contain.
I know of programs like Zenity, but I think it's doesn't give me what I want. For example, if I were to use it for the first script, it'll end up flashing sequence of windows in succession rather than getting everything done from a single window.
So, basically I'm looking at some corss-platform program that lets me create a window from a text description, probably XML or the like. Please suggest.
Thanks
Jeenu
Mozilla's XUL is a cross platform application framework - . You could write an app as a Firefox plugin or a standalone XUL application.
mono and monodevelop could work for this. Or even something super simple like shoes.

Resources