0

I would like some assistance to write an AppleScript to automatically redirect amazon.com to smile.amazon.com. I tend to always forget to use smile. With this automator I will never forget to. Unfortunately I am new to using the tool.

| improve this question | | | | |
  • Amazon has a browser extension that will do this for you, among other things. It's called Amazon Assistant: amazon.com/gp/BIT – TJ Luoma Jul 19 '19 at 19:53
1

REVISED SOLUTION

This following solution is to be used with Google Chrome.

Paste this following AppleScript code into a new Script Editor.app document then save it as a "Stay Open" application.

Double-clicking this new application in Finder, will launch Google Chrome if it is not already running. It will immediately then start monitoring the URLs of every tab in window 1 of Google Chrome. Whenever the URL of any tab starts with https://www.amazon.com, is detected, it will automatically be redirected to https://smile.amazon.com . When Google Chrome is no longer running, the application will quit on it's own.

The first time you open your new applet, be sure to choose the option for allowing it to run... on any system dialogs which may pop-up on first launch.

This AppleScript code works for me using the latest version of macOS Mojave.

on run
    tell application "Google Chrome" to launch
end run

on idle
    if application "Google Chrome" is not running then quit me
    tell application "Google Chrome" to tell window 1
        try
            set amazonTabs to (tabs whose URL starts with "https://www.amazon")
            delay 0.1
            if amazonTabs is not {} then
                set URL of item 1 of amazonTabs to "https://smile.amazon.com"
            end if
        end try
    end tell
    if application "Google Chrome" is not running then quit me
    return 0.5
end idle

on quit
    continue quit -- allows the script to quit
end quit

Due to some comments on the original code of my solution using too much of the computer resources, I believe the above code no longer produces those issues.

enter image description here

Safari Version

on run
    tell application "Safari" to launch
end run

on idle
    if application "Safari" is not running then quit me
    tell application "Safari" to tell window 1
        try
            set amazonTabs to (tabs whose URL starts with "https://www.amazon")
            delay 0.1
            if amazonTabs is not {} then
                set URL of item 1 of amazonTabs to "https://smile.amazon.com"
            end if
        end try
    end tell
    if application "Safari" is not running then quit me
    return 0.5
end idle

on quit
    continue quit -- allows the script to quit
end quit

To be able to control Safari using AppleScript, be sure to enable "Show Develop menu in menu bar" in Safari's Preferences.

enter image description here

You'll also need to select "Allow JavaScript from Apple Events" in Develop menu bar item.

enter image description here

| improve this answer | | | | |
  • 1
    While technically this works nonetheless, it's really not the way to go as this type of AppleScript application is resource intensive. Running this immediately caused the fans to spin up on my MacBook Pro and consumed 88% of the CPU and continued to increase the longer it stayed open. IMO The real answer to the question was to tell the OP to either condition themself to typing the proper URL or use a bookmark, after all that's what bookmarks are for! As a crutch, it would be far better to do an AppleScript app that just opens a window to the target URL and place in the Dock with a smiley icon. – user3439894 Jul 19 '19 at 9:49
  • I have a good amount of resources on my laptop but the last thing I want is for the resource to get used up for no reasons. I do have a bookmark but I always forget to click on it. – nickyung Jul 19 '19 at 12:42
  • @user3439894 . Let me know if you are having the same issues with my revised code please. – wch1zpink Jul 19 '19 at 15:57
  • I want to try it but I do not have google chrome installed nor do I need it. I don't trust google but nevertheless, can I just replace google with safari everywhere in the code. – nickyung Jul 19 '19 at 18:33
  • Thank you for taking the time to do this. I need to find some tutorials and learn how to use it. – nickyung Jul 19 '19 at 18:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .