Jump to content

Trouble with Google Chrome vs. Safari workflow


Recommended Posts

Hi all, 

 

I've been an Alfred user for quite some time, but never a power user. I've recently started taking Alfred more seriously as a productivity tool, and I came across a script by @senhortavares, that retrieves a title, a URL from the web, and downloads it as markdown, creating an Obsidian file. The start of the workflow starts like this with Safari, and it works flawlessly. Then, there's a curl, an html2text step, and finally everything put down in a file.

 

tell application "Safari" to set currentURL to the url of the front document
tell application "Safari" to set theTitle to name of front document

set bundleID to (system attribute "alfred_workflow_bundleid")

tell application id "com.runningwithcrayons.Alfred"
    set configuration "url" to value currentURL in workflow bundleID
    set configuration "title" to value theTitle in workflow bundleID
end tell

 

For some reason, after allowing Chrome to accept JS events from Apple Events (View > Developer > Allow JavaScript from Apple Events), it does not work in Chrome. Not as (AS), nor as (JS). Replacing Safari with Google Chrome should work just fine, as far as my understanding goes. 


Any thoughts on what could be wrong to fix this first step?

 

Thanks in advance and Happy New Year! 😁

Link to post
35 minutes ago, alvaroybanez said:

Replacing Safari with Google Chrome should work just fine, as far as my understanding goes.

 

Not so, I'm afraid. You need to use different commands with Chromium-based browsers. The instructions for getting page URL & title from various browsers via AppleScript are stickied at the top of this forum:

 

 

Link to post
4 minutes ago, deanishe said:

 

Not so, I'm afraid. You need to use different commands with Chromium-based browsers. The instructions for getting page URL & title from various browsers via AppleScript are stickied at the top of this forum:

 

 

Thanks! 


I checked that post before asking a question, but the tell seems to be pretty straight forward for the browser. Retrieve the URL and the title. The syntax in that post's example regarding Google Chrome says: tell application "Google Chrome" to return title of active tab of front window, which is, more or less, close to the syntax that AS is passing to Safari. The rest is handled by Alfred. Maybe I'm missing something (I have zero experience with AS).

 

 

Link to post
10 minutes ago, alvaroybanez said:

 which is, more or less, close to the syntax that AS is passing to Safari. […] Maybe I'm missing something

 

Don't be fooled by AppleScript looking a bit like English. It's still a programming language, so "close" isn't good enough. It has to be exactly right or it won't work.

Link to post
3 hours ago, deanishe said:

 

Don't be fooled by AppleScript looking a bit like English. It's still a programming language, so "close" isn't good enough. It has to be exactly right or it won't work.


that I get. I’ll have to dig deeper. The chromium documentation regarding Apple script is pretty shallow. Thanks again and a happy new year! 

Link to post
18 hours ago, alvaroybanez said:


that I get. I’ll have to dig deeper. The chromium documentation regarding Apple script is pretty shallow. Thanks again and a happy new year! 

 

21 hours ago, deanishe said:

 

Don't be fooled by AppleScript looking a bit like English. It's still a programming language, so "close" isn't good enough. It has to be exactly right or it won't work.

 

 

I got it to work, if anyone from the Obsidian forum is wondering, the two Safari tells need to be replaced with: 

 

tell application "Google Chrome" to set currentURL to URL of active tab of window 1
tell application "Google Chrome" to set theTitle to title of active tab of window 1

 

I've also shared the finding with the script creator so he might update his repo. 

Thanks! 

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...