Last active
February 12, 2017 10:35
-
-
Save troutcolor/8a09550f08a34e179bec to your computer and use it in GitHub Desktop.
Makes auto complete google search gifs, needs gifsicle
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
--needs gifsicle http://www.lcdf.org/gifsicle/ | |
-- updated for retina screen | |
set thetext to text returned of (display dialog "What do you want to autocomplete?" default answer "I hate") | |
set theFileName to change_case_of(thetext, "lower") & ".gif" | |
set tempdir to POSIX path of (path to temporary items from user domain) & "autogifs/" | |
try | |
do shell script "mkdir " & tempdir | |
end try | |
set alphabet to {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"} | |
set vowels to "aeiou" | |
tell application "Safari" | |
activate | |
tell application "System Events" | |
tell process "Safari" | |
click menu item "New Private Window" of menu "File" of menu bar 1 | |
end tell | |
end tell | |
set bounds of window 1 to {0, 0, 800, 600} | |
set the URL of the front document to "http://google.co.uk" | |
delay 5 | |
tell application "System Events" | |
keystroke thetext | |
end tell | |
repeat with letter in alphabet | |
set typing to " " & letter | |
set tfile to tempdir & letter & ".gif" | |
tell application "System Events" | |
keystroke typing | |
delay 1 | |
do shell script "screencapture -t GIF " & tfile | |
keystroke (ASCII character 8) | |
keystroke (ASCII character 8) | |
end tell | |
end repeat | |
end tell | |
if isRetina() then | |
do shell script "/usr/local/bin/gifsicle --delay 90 --colors 128 --loopcount --crop 0,200+1600x320 --resize 800x160 " & tempdir & "* > ~/Desktop/" & theFileName | |
else | |
do shell script "/usr/local/bin/gifsicle --delay 90 --colors 128 --loopcount ---crop 0,100+800x160 " & tempdir & "* > ~/Desktop/" & theFileName | |
end if | |
-- | |
--clean up | |
do shell script "rm -rf " & tempdir | |
--do shell script "open " & tempdir | |
on isRetina() | |
set ret to (do shell script "system_profiler SPDisplaysDataType | awk '/Retina:/{print $2}'") | |
if ret is "Yes" then | |
return true | |
else | |
return false | |
end if | |
end isRetina | |
on change_case_of(this_text, this_case) | |
if this_case is "lower" then | |
set the comparison_string to "ABCDEFGHIJKLMNOPQRSTUVWXYZ " | |
set the source_string to "abcdefghijklmnopqrstuvwxyz_" | |
else | |
set the comparison_string to "abcdefghijklmnopqrstuvwxyz" | |
set the source_string to "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
end if | |
set the new_text to "" | |
repeat with thisChar in this_text | |
set x to the offset of thisChar in the comparison_string | |
if x is not 0 then | |
set the new_text to (the new_text & character x of the source_string) as string | |
else | |
set the new_text to (the new_text & thisChar) as string | |
end if | |
end repeat | |
return the new_text | |
end change_case_of |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment