Last active
August 29, 2015 14:18
-
-
Save JenniferMack/38db468940e0c8ea7320 to your computer and use it in GitHub Desktop.
Apple Automator script to post to WordPress from Ulysses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'xmlrpc/client' | |
wordpress = XMLRPC::Client.new_from_hash( | |
{ "host" => "yourblogurl", | |
"user" => "yourWPusername", | |
"password" => "yourWPpassword", | |
"use_ssl" => nil, #change to true if hosted on SSL | |
#-------------------------------------------------------# | |
"path" => "/xmlrpc.php" | |
}) | |
post = [] | |
content = {} | |
ARGV.each do |f| | |
File.open(f, :encoding => "UTF-8") do |file| | |
file.each_line do |line| | |
next if "\n" == line | |
post << line.chomp.gsub(/(a\W+)(href="[^#])/, '\1target="_blank" \2') | |
end | |
end | |
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