Applescript to copy info from MarsEdit

Micro.Blogger @hutaffe asked:

Is there a MarsEdit plugin or something that helps to quickly share a Link and title with some highlighted text for Firefox?

Update: after researching and writing the following I realised I had the question totally back to front. @hutaffe wants to select something in Firefox and send it to Mars Edit. Anyway, I hope the following is helpful for someone.

Use Applescript

My answer is: Here, have an Applescript.

The one tricky thing is the selected text. For my script you need to select some text and copy it then run the script.

Here's the actual Applescript:

tell application "MarsEdit"
    
    -- first *copy* the text from the post that you want to include
    
    
    tell selected post
        
        -- clear variables
        set myTitle to ""
        set myLink to ""
        set myPub to ""
        set myText to ""
        
        
        -- grab info and load into variables
        -- put each bit on a new line
        set myTitle to return & "Title: " & title
        set myLink to return & "Link: " & permalink
        set myPub to return & "Published: " & published date
        set myText to return & "Quote: " & (the clipboard) -- this is the selection you copied
        
        
        -- assemble into a chunk ready to paste elsewhere
        set the clipboard to myTitle & myLink & myPub & myText
        
    end tell
    
    
end tell 

Here's a screenshot:

MarsEdit Applescript screenshot.
MarsEdit Applescript screenshot.

The script copies Title, Permalink, Publication Date and your previously selected and copied text and puts it all on the clipboard ready to paste somewhere. I ran the script and then pasted to BBEdit, my text editor of choice.

Script results pasted to BBEdit.
Script results pasted to BBEdit.

How and where to run the script

For this Applescript you first copy some text then select a published post in the Main Window of Mars Edit, then run the script.

Selected post and text in MarsEdit main window.
Selected post and text in MarsEdit main window.

You can run the script direct from Script Editor (check tthe Utilities folder inside the main Applications folder on your Mac).

I usually run scripts via Keyboard Maestro where I can use a small scripts palette or assign a keystroke. Another option would be Red Sweater's own FastScripts (free for up to 10 shortcuts).

The script itself

Either copy the script above and paste into Script Editor, or email me and I'll send the script: miraz@firstbite.co.nz . (Once I figure out something better I'll add a link to simply download it.)

Miraz Jordan @Miraz

Please take a look at my Love Waikawa Beach website too.