Post to WordPress from Ulysses using the xmlrpc interface.
#!/usr/bin/env ruby | |
require 'xmlrpc/client' | |
wordpress = XMLRPC::Client.new_from_hash( | |
{ "host" => "yourblogname", | |
"user" => "yourWPusername", | |
"password" => "yourWPpassword", | |
"use_ssl" => nil, #change to true if hosted on SSL | |
#-------------------------------------------------------# | |
"path" => "/xmlrpc.php" | |
}) | |
post = [] | |
content = {} | |
ARGF.each_line do |line| | |
next if "\n" == line | |
post << line.chomp.gsub(/(a\W+)(href="[^#])/, '\1target="_blank" \2') | |
end | |
content["title"] = post.shift.gsub(/<\/*h1>/, '') | |
content["mt_keywords"] = post.shift.gsub(/<\/*p>/, '').split(/,\s*/) | |
content["description"] = post.join("\n\n").sub(/<p>MORE<\/p>/, '<!--more-->') | |
begin | |
postnum = wordpress.call( | |
'metaWeblog.newPost', | |
0, | |
wordpress.user, | |
wordpress.password, | |
content, | |
false # false for draft, true for publish | |
) | |
puts "Posting Success! (##{postnum})" | |
rescue => err | |
puts "Posting error: #{err}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
This is the fastest way to get HTML from Ulysses to WordPress.
Notes:
All links will have
target=“_blank”
added to them.Change
use_ssl
totrue
if you’re blog is on SSL capable host.Change line 33 to
true
if you want it published when posted. Draft is the default.Usage:
In Ulysses, copy as html or use the export panel. Make sure it’s set for “snippet.” Then from the terminal do :
pbpaste | wp-post.rb
This will also work as an Automator action, and the output is notification center friendly.