Michael Henley ([info]automagical) wrote,

AppleScript calling LiveJournal

Here's a simple script I wrote that you can use to post directly to LiveJournal from AppleScript. This is only a small example of how you can interact with LiveJournal using AppleScript. For more information on their XML-RPC implementation and syntax, look here. Remember that AppleScript treats structs as {{|records|:within, |single|:parameters}}, and don't forget to |pipe| all your labels (which should match LJ's xml fields) to prevent scripting addition conflicts.
-- the name of your livejournal account
set my_name to "YOUR USERNAME"

-- the subject line for you entry:
set my_topic to "I'm Awesome!"

-- the body of your entry:
set my_post to "I posted this directly from AppleScript using LiveJournal's XML-RPC API. Kickass."

-- password dialog (sent in the clear, see LJ docs for safer methods)
copy {text returned of (display dialog "Enter password for " & quoted form of my_name with title ¬
	"LiveJournal Post Event" with icon stop default answer "" with hidden answer), "clear"} to ¬
	{my_pass, my_auth}

-- figure out the time and date of your post based on local system time
set post_time to time of (current date)
if post_time ≥ hours then
	copy {post_time div hours, post_time mod hours} to ¬
		{my_hour, minute_x}
	copy {minute_x div minutes, minute_x mod minutes} to ¬
		{my_minute, my_second}
else if post_time ≥ minutes then
	copy {0, post_time div minutes, post_time mod minutes} to ¬
		{my_hour, my_minute, my_second}
else
	copy {0, 0, post_time} to {my_hour, my_minute, my_second}
end if
current date
copy {year of result, month of result as integer, day of result} to {my_year, my_month, my_day}

-- the actual post event
tell application "http://www.livejournal.com/interface/xmlrpc" to call xmlrpc ¬
	{method name:"LJ.XMLRPC.postevent", parameters:¬
		{{username:my_name, auth_method:my_auth, |password|:my_pass, |event|:¬
			my_post, lineendings:"mac", subject:my_topic, security:"", allowmask:0, |year|:¬
			my_year, mon:my_month, |day|:¬
			my_day, hour:my_hour, min:my_minute}}}

-- open the entry in your default browser
open location (|url| of result)

x-posted

  • Post a new comment

    Error

  • 0 comments
Create an Account
Forgot your login or password?
Facebook Twitter More login options
English • Español • Deutsch • Русский…