Last year I wrote a script (original, improved) which posted the selected tweet to MarsEdit from Twitterrific via AppleScript.
Here’s the same script, but I switched out Hibari for Twitterrific and JSTalk for AppleScript:
var t = [[JSTalk application:'Hibari'] selectedTweet];
var output = '['+t.name+' / @'+t.screenName+']'
+'(https://twitter.com/'+t.screenName+'/status/'+t.tweetID+'):\n'
+'> '+t.tweetHTML;
var marsEdit = [SBApplication application:'MarsEdit'];
var firstDocument = [[marsEdit documents] objectAtIndex:0];
var input = [firstDocument selectedText];
if ([input length] > 0) {
input += '\n\n';
}
output = [input stringByAppendingString:output];
[firstDocument setSelectedText:output];
I call [input stringByAppendingString:output] instead of just writing input + output due to what looks like an interaction bug between JSCocoa and Scripting Bridge.
It appears Scripting Bridge attribute proxies representing empty strings get concatenated as '0' instead of ''. Calling stringByAppendingString: works-around the bug.
Another thing is that MarsEdit doesn’t seem willing to execute a .jstalk file even after I set its executable bit — it assumes it’s an AppleScript and dies with a syntax error. So instead I invoke the script via FastScripts, which has no such problem.
About a month back I wrote and posted an AppleScript that makes it easy to blog up a tweet. I wrote:
I haven’t used the script yet, and may never. It’s more an interesting experiment to have it lying around to see if it comes in handy.
Turns out it’s very handy, and I’ve made great use of it.
But it’s been annoying that the script creates a new blog posting each time it’s invoked, so I tweaked it to just inject the quoted tweet into the frontmost document. Enjoy:
property kReturn : ASCII character 13
tell application "Twitterrific"
set t to selection
set tweetScreenName to screen name of t
set tweetUserName to user name of t
set tweetID to id of t
set tweetText to text of t
end tell
tell application "MarsEdit"
set input to selected text in document 1
set output to "[" & ¬
tweetUserName & ¬
" / @" & ¬
tweetScreenName & ¬
"](" & "https://twitter.com/" & ¬
tweetScreenName & ¬
"/status/" & tweetID & "):" & ¬
kReturn & ¬
"> " & tweetText
if length of input > 0 then
set output to kReturn & kReturn & output
end if
set (selected text in document 1) to input & output
end tell
MarsEdit doesn’t have an “Indent Right” command. However, inserting a tab before each line is how to represent code in Markdown. So I wrote a script to make it easier:
tell application "MarsEdit"
set input to selected text in document 1
set output to ""
repeat with inputLine in (paragraphs of input)
set output to output & (ASCII character 9) & inputLine & (ASCII character 13)
end repeat
set (selected text in document 1) to output
end tell
Nicely recursive: I just used the above script to indent the above script.
Though instead of putting it into ~/Library/Application Support/MarsEdit/Scripts, I put it into ~/Library/Scripts/Applications/MarsEdit/Indent Right.scpt where I bind it to ⌘] in FastScripts.
Ahh, just like BBEdit and Xcode…
Came upon the idea of making it easy to create a new blog entry in MarsEdit by quoting the currently-selected tweet in Twitterrific. Wasn’t too hard, only stubbed my toe twice (this is doing very well when dealing with AppleScript).
property kReturn : ASCII character 13
tell application "Twitterrific"
set t to selection
set tweetScreenName to screen name of t
set tweetUserName to user name of t
set tweetID to id of t
set tweetText to text of t
end tell
tell application "MarsEdit"
set newDocument to make new document
tell newDocument
set body to "[" & ¬
tweetUserName & ¬
" / @" & ¬
tweetScreenName & ¬
"](" & "https://twitter.com/" & ¬
tweetScreenName & ¬
"/status/" & tweetID & "):" & ¬
kReturn & ¬
"> " & tweetText
end tell
end tell
I had to copy the properties out of the selected tweet (t) into local variables since once I switched scopes from Twitterrific to MarsEdit, AppleScript complained about how it couldn’t access the fields. This is probably because the property names have spaces in them. Sigh.
I haven’t used the script yet, and may never. It’s more an interesting experiment to have it lying around to see if it comes in handy.