[Action Request] Send email to one address with subject text from LB

Sharing and discussing custom actions for LaunchBar
richtack
Posts: 5
Joined: Sat Feb 06, 2016 7:32 pm

[Action Request] Send email to one address with subject text from LB

Postby richtack » Sat Feb 06, 2016 7:38 pm

I am trying to create a custom action that will automatically create a new email to a fixed address with the subject line being the text I enter into launchbar. I am enough of a geek to modify someone else's code, but not enough of a geek to figure out how to write a custom action from scratch.

I have an applescript to do this, but I don't know how to integrate this into Launchbar custom actions, or get the variable I need from launchbar to the script.

(If anyone is interested, I want to do this to automatically create tasks in "Remember The Milk" using the email tasks function.) I need the Launchbar text to be in the subject of the email, not the body.

Can anyone point me to another custom script, maybe already posted here, that I can download and modify? I have looked but have not found anything.

BTW, I know I can select the email address in Launchbar and enter text, but that puts the text into the message body, which doesn't help me.

thanks in advance,
Rich

raguay
Rank 1
Rank 1
Posts: 32
Joined: Fri Jul 18, 2014 11:08 am

Re: [Action Request] Send email to one address with subject text from LB

Postby raguay » Mon Feb 08, 2016 5:18 am

If you have an AppleScript file already, you can run it from an action using Launchbar.executeAppleScriptFile(<path to file>, <arg1>, <arg2>,...) in the action. The Action Editor will create the skeleton file for the action. By adding the file to the action in the ActionEditor, you path would just be a reference to the file directly.

https://developer.obdev.at/launchbar-de ... -launchbar

The action would look something like this:

Code: Select all

// LaunchBar Action Script

function run(argument) {
    if (argument == undefined) {
        // Inform the user that there was no argument
        LaunchBar.alert('No argument was passed to the action');
    } else {
        // Return a single item that describes the argument
        LaunchBar.executeAppleScriptFile("email.scpt",argument);
    }
}


Where email.scpt is the name of your script file placed inside the action. I hope this helps.
Last edited by raguay on Wed Feb 10, 2016 6:58 am, edited 1 time in total.

richtack
Posts: 5
Joined: Sat Feb 06, 2016 7:32 pm

Re: [Action Request] Send email to one address with subject text from LB

Postby richtack » Mon Feb 08, 2016 6:19 pm

Thanks for this!

I'm still doing something wrong, and I'm not sure what. When I run it, I'm getting
ReferenceError: Can't find variable: Launchbar (line 9).
It looks to be either the location of the file where I saved the applescript, or the way I am passing the argument.

I took your code and changed my default.js to be:

Code: Select all

// LaunchBar Action Script

function run(argument) {
    if (argument == undefined) {
        // Inform the user that there was no argument
        LaunchBar.alert('No argument was passed to the action');
    } else {
        // Return a single item that describes the argument
        Launchbar.executeAppleScriptFile("/Macintosh HD/Users/richtack/Library/Scripts/rtmemail.scpt",argument);
    }
}


My rtmemail.scpt looks like this:

Code: Select all

tell application "Finder"
   
   set subject_ to !str
   set the_content to ""
   tell application "Mail"
      set newMessage to make new outgoing message with properties {subject:subject_, content:the_content & return & return}
      tell newMessage
         
         set visible to true 
         set sender to "r***********k@me.com"
         make new to recipient at end of to recipients with properties {address:"r***************b@rmilk.com"}
         
         (* change save to send to send*)
         send --<<<<---------------- change save to send to send or send to save to save to drafts
         (* change save to send to send*)
      end tell
   end tell
end tell



I have to imagine you're busy, but if you have a minute, it would be super helpful. I am hoping I can figure this out myself. (Which was the thinking in choosing Launchbar over Alfred.)

thanks!
Rich

You

raguay
Rank 1
Rank 1
Posts: 32
Joined: Fri Jul 18, 2014 11:08 am

Re: [Action Request] Send email to one address with subject text from LB

Postby raguay » Tue Feb 09, 2016 6:59 am

You AppleScript needs to be:

Code: Select all

on run argv
   set subject_ to argv
   set the_content to ""
   tell application "Mail"
      set newMessage to make new outgoing message with properties {subject:subject_, content:the_content & return & return}
      tell newMessage
         
         set visible to true
         set sender to "r***********k@me.com"
         make new to recipient at end of to recipients with properties {address:"r***************b@rmilk.com"}
         
         (* change save to send to send*)
         send --<<<<---------------- change save to send to send or send to save to save to drafts
         (* change save to send to send*)
      end tell
   end tell
end run


The argv is the command line given. Your script never receives the command line arguments and the str variable is not set anywhere. You also do not need the "tell Finder" section. That just slows the script down. I hope this helps.

For people that aren't program savy, I would recommend Alfred due to it being easy to create scripts like this. Launchbar is more program intensive and therefore a little harder for new programmers. I actually use both. Somethings are easier on Alfred, somethings are easier and faster in Launchbar. Therefore, I have the best of both on my system!

richtack
Posts: 5
Joined: Sat Feb 06, 2016 7:32 pm

Re: [Action Request] Send email to one address with subject text from LB

Postby richtack » Tue Feb 09, 2016 6:10 pm

Thanks again for your help. I am still getting the same error. I suspect I am doing something wrong that is super obvious if I was adept at coding. I'm sure I'm formatting something incorrectly.

Instead of pestering the forum for more specifics, do you know of any other custom actions that pass a text string to a simple applescript? If I installed similar handiwork, I think I could figure out what I'm doing wrong.

Also, I have seen the LB documentation, but are there any basic tutorials for starting to learn this kind of scripting before "google, and find and replace"? I find this all very interesting, but I don't know where to start!

raguay
Rank 1
Rank 1
Posts: 32
Joined: Fri Jul 18, 2014 11:08 am

Re: [Action Request] Send email to one address with subject text from LB

Postby raguay » Wed Feb 10, 2016 6:57 am

I packaged the whole action up for you. You can download it here: https://db.tt/j7AZjWiK

The LaunchBar action script I had above had a typo: it should be LaunchBar and not Launchbar. It is corrected in the action here for download and edited the above post. You will need to go inside the action and edit the script for the correct email address. Unzip the file, then right click on the "Send Subject Email.lbaction" file and select "Show Package Contents". The scripts are in the "Scripts" subdirectory. Alternatively, you can access the scripts from the Script Editor.

I wrote a short tutorial on LaunchBar 6 actions when LaunchBar 6 came out: http://computers.tutsplus.com/tutorials ... -cms-22733

That was before the Action Editor. Hopefully, my editor will let me do an update to it.

richtack
Posts: 5
Joined: Sat Feb 06, 2016 7:32 pm

Re: [Action Request] Send email to one address with subject text from LB

Postby richtack » Wed Feb 10, 2016 5:16 pm

OMG, thank you for this!

Actually, I correct my script with the LaunchBar typo, and it immediately worked. It felt really good to just see the whole thing come together, exactly as I want it to work, just by fixing a 'b'. I dl'ed your zip, just to see if I screwed anything else up, but I think I had the rest correct. I really appreciate your help. in a way, all the dorking around because of the typo forced me to learn a number of things about js and applescript.

I will definitely check out your tutorial over the weekend. I hope you get to update it. I doubt I am alone in this world - nerdy enough to want to play, but don't have the time to learn to be a full-out programmer!

BTW, I have to think there are many uses for this LBaction, for people who have to dash off multiple emails to the same person (like an assistant, spouse, bot, etc.)

thanks again,
rich

brijazz
Posts: 1
Joined: Tue Dec 27, 2016 2:22 pm

Re: [Action Request] Send email to one address with subject text from LB

Postby brijazz » Tue Dec 27, 2016 2:25 pm

Glad I found this thread, I'm looking for an action just like this! @raguay, is there any chance you can repost the download link for the action you whipped up? Looks like the link you have a couple of posts up is no longer valid.


Return to “LaunchBar Actions”

Who is online

Users browsing this forum: No registered users and 2 guests