Safari to Byword

This community is so helpful that I’ve moved from KM novice to a semi-master – thanks directly to the replies I’ve had to my queries thus far. So when I came up with a new process to automate I thought I’d come back to you. Here’s my scenario:

  • I’m reading an article in Safari (usually on Feedly or in Pocket) that I want to blog about.
  • I copy the URL, open Byword, and paste it there.
  • I go back to Safari, copy the title of the article, go back to Byword, and paste it there.
  • I write a paragraph about the article, usually with plenty of quotations from the article.
  • I publish it from Byword directly to my Wordpress blog (as a Draft, which I then edit it in my browser (to add images and so on).

You can see the outcome in a post like this.

So now (you guessed it) I’d like to automate the bolded components and the application-switching and the publishing from Byword. I suspect it’s going to involve variables and clipboards. And for what it’s worth, I’m writing in Markdown.

Thoughts?

yours
Michael

1 Like

Though page title isn’t necessarily synonymous with article title, I frequently use a KM macro to grab the title and URL of the current webpage. I find it kind of handy since Safari doesn’t have to be at the front; I can read something online then take notes on it my writing app of choice and still grab what I need as long as I leave that tab open. I probably could’ve made this a bit more elegant, but it seems to suit my needs. I just use an AppleScript action with the code shown below. Maybe it’ll help. — Ian

tell application "Safari"
  set {webpage_name, webpage_url} to document 1's {name, URL}
  set the clipboard to webpage_name & "  |  " & webpage_url
  tell application "Keyboard Maestro Engine" to make variable with properties {name:"kmVar", value:the clipboard}
end tell
1 Like

If you’re going to bring the text into Keyboard Maestro then you might as well skip the clipboard.

------------------------------------------------------------
tell application "Safari"
  set {webpage_name, webpage_url} to document 1's {name, URL}
  set kmValue to webpage_name & "  |  " & webpage_url
end tell
------------------------------------------------------------
tell application "Keyboard Maestro Engine"
  try
    set value of variable "kmVar" to kmValue
  on error
    make variable with properties {name:"kmVar", value:kmValue}
  end try
end tell
------------------------------------------------------------

Alternatively

------------------------------------------------------------
tell application "Safari" to set {webpage_name, webpage_url} to document 1's {name, URL}
tell application "Byword" to activate
return webpage_name & "  |  " & webpage_url
------------------------------------------------------------

And select Paste as the outcome of the Execute an AppleScript action.

You can also get the text of the front Safari document and parse it for the title if there’s something consistent.

OR

You can get the source of the front Safari Document and parse it for the title.

OR

You might be able to use JavaScript and Xpath to find what you’re looking for.

Safari is pretty scriptable, so there are a fair number of options.

-Chris

2 Likes