Created
May 12, 2014 11:02
-
-
Save crmne/5855a901a0a9a6ef30a5 to your computer and use it in GitHub Desktop.
A tool to add websites to Safari Power Saver's whitelist.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on number_to_string(this_number) | |
set this_number to this_number as string | |
if this_number contains "E+" then | |
set x to the offset of "," in this_number | |
set y to the offset of "+" in this_number | |
set z to the offset of "E" in this_number | |
set the decimal_adjust to characters (y - (length of this_number)) thru ¬ | |
-1 of this_number as string as number | |
if x is not 0 then | |
set the first_part to characters 1 thru (x - 1) of this_number as string | |
else | |
set the first_part to "" | |
end if | |
set the second_part to characters (x + 1) thru (z - 1) of this_number as string | |
set the converted_number to the first_part | |
repeat with i from 1 to the decimal_adjust | |
try | |
set the converted_number to ¬ | |
the converted_number & character i of the second_part | |
on error | |
set the converted_number to the converted_number & "0" | |
end try | |
end repeat | |
return the converted_number | |
else | |
return this_number | |
end if | |
end number_to_string | |
display dialog "Which website would you like to start plug-ins automatically on?" default answer "soundcloud.com" with title "Safari Power Saver Whitelister" | |
set theWebsite to text returned of result | |
-- in the original plist this looks like a random ID. unfortunately I don't know the boundaries of this number, so I'm guessing based on my existing values. Let me know if doesn't work for you. | |
set theKey to number_to_string(random number from 1.0E+9 to 3.0E+9) -- should be a string | |
-- in the original plist this looks like a UNIX timestamp of now + 30 days, maybe an expiration date for the whitelisted website? | |
set theValue to ((do shell script "date +%s") as integer) + 2592000 -- should be an integer | |
tell application "System Events" | |
set plistFile to property list file "~/Library/Safari/PlugInOrigins.plist" | |
tell plistFile | |
set the parentDic to make new property list item at end of property list items of contents of plistFile with properties {kind:record, name:theWebsite} | |
tell parentDic | |
make new property list item at end of property list items of contents of parentDic with properties {kind:number, name:theKey, value:theValue} | |
end tell | |
end tell | |
end tell | |
display dialog "Success! Plug-ins will now start automatically also on " & theWebsite buttons {"OK"} with title "Safari Power Saver Whitelister" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment