Jump to content
JolinM

Trigger javascript with a hotkey

Recommended Posts

Hi, I am trying to trigger the instapaperizing action from Alfred.

I seted up a hotkey, followed by either a run script action or an open page in browser, with this code inside, but nothing seams to work… any clue?

 

Thanks!

 

 

javascript:function%20iptxt()%7Bvar%20d%3Ddocument%3Btry%7Bif(!d.body)throw(0)%3Bwindow.location%3D%27http://www.instapaper.com/text%3Fu%3D%27%2BencodeURIComponent(d.location.href)%3B%7Dcatch(e)%7Balert(%27Please%20wait%20until%20the%20page%20has%20loaded.%27)%3B%7D%7Diptxt()%3Bvoid(0)
 

 

Share this post


Link to post

Hi, I am trying to trigger the instapaperizing action from Alfred.

I seted up a hotkey, followed by either a run script action or an open page in browser, with this code inside, but nothing seams to work… any clue?

 

Thanks!

 

 

javascript:function%20iptxt()%7Bvar%20d%3Ddocument%3Btry%7Bif(!d.body)throw(0)%3Bwindow.location%3D%27http://www.instapaper.com/text%3Fu%3D%27%2BencodeURIComponent(d.location.href)%3B%7Dcatch(e)%7Balert(%27Please%20wait%20until%20the%20page%20has%20loaded.%27)%3B%7D%7Diptxt()%3Bvoid(0)
 

 

I'm assuming that you are just trying to "open" this? I would assume that OSX probably doesn't know how to handle that because javascript exists in the browser and not OS-wide. You can still do it though.

 

Try this instead.

tell application "Safari" to do JavaScript "javascript:function iptxt(){var d=document;try{if(!d.body)throw(0);window.location='http://www.instapaper.com/text?u='+encodeURIComponent(d.location.href);}catch(e){alert('Please wait until the page has loaded.');}}iptxt();void(0)" in the current tab of the front window

 

That triggers the javascript to run in the current tab of the front window in Safari (assuming that's what your using). We may have to tweak it a little bit if you aren't using Safari but I would think it would still be possible in the other browsers.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...