Jump to content

How to assign a hotkey to run a script


Recommended Posts

Excuse my ignorance: I've never used Applescripts apart from just double-clicking them in Finder and running them.  In Alfred 1 I set up a hotkey to take the current URL in an open Safari browser window and open it in Chrome.  All I did was to choose the hotkey, then browse to the .scpt file (previously downloaded and saved in ~/Library/Scripts/Safari) and select it.

 

In Alfred 2 there doesn't appear to be a similar capability.  You only seem to be able to actually write a script, rather than just point to one that has already been created and saved as a .scpt file.  I have tried setting up a workflow, and pasting the script into the 'run script' action window, but that doesn't work.

 

What am I supposed to do.  Is there a way of just pointing to the .scpt file and running it, like before?

 

Any help gratefully received.

 

Thanks, Kevan

 

 

PS: here's the actual script, for what it's worth:

 

 

property theURL : ""
tell application "Safari"
   set theURL to URL of current tab of window 1
end tell
tell application "Google Chrome"
   if (count of (every window where visible is true)) is greater than 0 then
      tell front window
         make new tab
      end tell
   else
      make new window
   end if
   set URL of active tab of front window to theURL
   activate
end tell

 

 

Link to comment

Excuse my ignorance: I've never used Applescripts apart from just double-clicking them in Finder and running them.  In Alfred 1 I set up a hotkey to take the current URL in an open Safari browser window and open it in Chrome.  All I did was to choose the hotkey, then browse to the .scpt file (previously downloaded and saved in ~/Library/Scripts/Safari) and select it.

 

In Alfred 2 there doesn't appear to be a similar capability.  You only seem to be able to actually write a script, rather than just point to one that has already been created and saved as a .scpt file.  I have tried setting up a workflow, and pasting the script into the 'run script' action window, but that doesn't work.

 

What am I supposed to do.  Is there a way of just pointing to the .scpt file and running it, like before?

 

Any help gratefully received.

 

Thanks, Kevan

 

 

PS: here's the actual script, for what it's worth:

 

 

property theURL : ""
tell application "Safari"
   set theURL to URL of current tab of window 1
end tell
tell application "Google Chrome"
   if (count of (every window where visible is true)) is greater than 0 then
      tell front window
         make new tab
      end tell
   else
      make new window
   end if
   set URL of active tab of front window to theURL
   activate
end tell

 

 

1. In Alfred's preferences, click the + in the lower left side and create a new Blank Workflow.

2. Set the name, author, and other details for the workflow.

3. Click the + in the top right of your workflow area, add a Input->Keyword. Set the details, make sure you set it to accept "No Argument"

4. Click the + in the top right, add an Action->Run Script.

5. In the Run Script config, set the language to /usr/bin/osascript, then paste in your AppleScript in the script area in the bottom.

6. Move your cursor to the right edge of the Keyword, a little tab should appear. Click and drag it to the Script. This will attach that keyword to that script.

 

Then, while in Safari, pop up Alfred and enter your keyword.

 

To assign a hotkey to this, click the + in the top right, add a Trigger->Hotkey. Set the hotkey, and save it. Then, same as above, drag the little tab from the hotkey to the script.

 

That should get you up and going.

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