Jump to content

I need a specific workflow that is safari related.

Recommended Posts

I felt that I am just here to make other people do stuff for me...


I have no idea how to make workflows... however I need a workflow that makes safari opens copied url and then directly jumped to reading mode. So I can copy everything into evernote later. I have tried to use evernote workflow, but sometimes it is not as clean as doing it separately. 


Here is what I normally do: 

  1. copy whatever url I need.
  2. use alfred to make safari opens a new window.
  3. paste that url in safari window.
  4. switch to reading mode.
  5. copy the whole page.


What I wanted to achieve:

  1. copy the url I need.
  2. open the new workflow.
  3. copy the whole page.


I want alfred to make safari open the last thing (in this case, a url) in my clipboard and then switched to reading mode automatically.


You can ask me more questions if I did not make myself clear.  


Link to comment

It's easy to open an new URL in Safari programatically, but Reader mode and copying the page can only be done by simulating user action.


Put the following script in a Run Script Action with Language = /usr/bin/osascript (AS) connected to your Hotkey/Keyword. It grabs the clipboard text, and if it's a URL, opens it in Safari, waits a bit, activates Reader mode, waits a little bit more, then triggers Select All and Copy. Uncomment the two lines at the end of the script to also close the Safari tab/window afterwards.


The big issue with this script (and this kind of scripting in general) is that there's no way to know when the page has loaded (Reader mode isn't available till it has), so the script just has to hope the page has loaded when it tries to enter Reader mode. Adjust the waitForLoad and waitForReader (both delays in seconds) settings at the top of the script if it's firing too quickly or too slowly.


-- How long to wait for page to load in Safari before

-- trying to activate Reader mode

property waitForLoad : 5

-- How long to wait for Reader mode to finish its animated loading

property waitForReader : 2


on run (argv)

    tell application "Safari"

        -- Get clipboard contents

        set theText to (the clipboard as text)

        -- Ensure it's a URL. This might fail if the URL is uppercase...

        if theText does not start with "http://" and theText does not start with "https://" then

            log "Invalid URL: " & theText

            -- Fail!

            return 1

        end if


        -- Open URL in Safari

        log "Opening " & theText


        open location theText

    end tell


    tell application "System Events"

        -- Activate Reader mode.

        -- Now it gets tricky. We have to guess how long to wait for the page to

        -- load, as Reader mode isn't available till it has (if then).

        delay waitForLoad

        -- CMD+SHIFT+R activates Reader mode

        keystroke "r" using {command down, shift down}

        -- Wait for animation

        delay waitForReader

        -- CMD+A to select all, then CMD+C to copy

        keystroke "a" using command down

        delay 0.2

        keystroke "c" using command down

        log "Page copied to clipboard"

        -- Uncomment the lines below to close the tab when done

        -- delay 0.4

        -- keystroke "w" using command down

    end tell

end run

Link to comment
On 08/03/2017 at 7:43 PM, deanishe said:


Dude... thank you so much... It worked like a charm...

I got a feeling that I may have to ask for more workflows down the road.... maybe I can donate to you some money??? 

I feel bad for you to do this for me...


Edit: I donated two dollars through packal. Hope you received it/ Thanks.. Will ask more sometime in the future. 

Edited by mrchow19910319
Link to comment

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...