[MacTUG] Applescript droplet to set Firefox homepage

Donald Duff-McCracken dsmccrac at uwaterloo.ca
Wed Aug 8 17:03:41 EDT 2018


Greetings, if you have a file called “policies.json” in Firefox.app/Contents/Resources/distribution you can set the homepage when you drag this copy of Firefox onto a new or rebuilt machine. (You may need to make the ‘distribution’ folder.)



I wrote a little applescript droplet. When you drop Firefox.app on it, it:

1) Ensures that you are not dropping a lot of things on it and that the thing you are dropping is called “Firefox.app”

2) creates the json file

3) saves it in the correct spot



It is pretty straightforward. I was going to attach the droplet but instead I will just append the applescript text after this note. To use, copy into script editor and save as an application (you can remember to deselect “show startup screen)”. If you are just interested in the structure of the json file, you can see it in the script.



As it is a really simple script you can give it the once over (and even if you are not an applescripter) you will see I am not doing anything malicious 😉



Feel free to let me know if there are issues (and solutions), but I would not suggest spending much time on how to make this x% more efficient/elegant!  (BTW you want me just to send you the droplet, let me know)



don





on open dropped_item

                     tell application "Finder"

                                    set item_count to length of dropped_item

                                    #ensure only one item is being dragged on droplet

                                    if item_count is greater than 1 then

                                                            display dialog "This droplet adds a custom homepage to Firefox. It appears you are dragging more than one item onto this droplet.



Please redo by dragging only the Firefox.app onto this droplet" buttons {"OK"} default button 1

                                                            error number -128

                                    else

                                                            set file_name to name of item dropped_item

                                                            #make sure item in question is named "Firefox.app"

                                                            if file_name is not equal to "Firefox.app" then

                                                                                    display dialog "This droplet only works with 'Firefox.app'"

                                                                                    error number -128

                                                            else

                                                                                    set dropped_item to the POSIX path of dropped_item

                                                                                    display dialog "This droplet sets a custom homepage for Firefox.



What is URL of homepage?" default answer "https://uwaterloo.ca"

                                                                                    set url_name to text returned of the result

                                                                                    set file_path to dropped_item & "Contents/Resources/distribution/"

                                                                                    do shell script "mkdir -p \"" & file_path & "\""

                                                                                    do shell script "cd \"" & file_path & "\"

cat >policies.json <<EOL

{

  \"policies\": {

    \"DisableAppUpdate\": true,

    \"DisplayBookmarksToolbar\": true,

    \"DisplayMenuBar\": true,

    \"DontCheckDefaultBrowser\": true,

    \"NoDefaultBookmarks\": true,

  \"OverrideFirstRunPage\": \"" & url_name & "\",

    \"Homepage\": {

      \"URL\": \"" & url_name & "\",

      \"Locked\": false

    }

  }

}

EOL"

                                                                                    set button_returned to button returned of (display dialog "When this copy of Firefox is deployed to new/rebuilt Macs, the homepage will be: " & url_name buttons {"More Info…", "OK"} default button 2)

                                                                                    if button_returned is "More Info…" then

                                                                                                            display dialog "This homepage was added by creating a file called 'policies.json' in '/Firefox.app/Contents/Resources/distribution'



Remove the 'distribution' folder if you wish to undo this." buttons {"OK"} default button 1

                                                                                    end if

                                                            end if

                                    end if

                     end tell

end open









------------------------------------

Donald Duff-McCracken

Technical Services Manager

Mapping, Analysis & Design

Faculty of Environment

University of Waterloo

(519) 888-4567 x32151

https://uwaterloo.ca/environment-computing/about/people

------------------------------------

This email communication is intended as a private communication for the sole use of the primary addressee and those individuals listed for copies in the original message. The information contained in this email is private and confidential and If you are not an intended recipient you are hereby notified that copying, forwarding or other dissemination or distribution of this communication by any means is prohibited.  If you are not specifically authorized to receive this email and if you believe that you received it in error please notify the original sender immediately.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.uwaterloo.ca/pipermail/mactug/attachments/20180808/28b54761/attachment-0001.html>


More information about the MacTUG mailing list