Created
November 30, 2012 09:05
-
-
Save cceddie/4174634 to your computer and use it in GitHub Desktop.
get Chrome tabs, write to executable bash file
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
-- gct: get chrome tabs | |
-- save FRONTMOST WINDOW of Chrome (or safari, but definitely not firefox) tabs into a file | |
-- optionally (by uncommenting) CLOSE the window | |
-- modified from http://www.leancrew.com/all-this/2012/10/saving-browser-tab-sets/ | |
-- ------------------------------------------------------------ | |
-- cce | |
-- 2012 nov- rev 0.2 | |
-- - why do i punish myself with applescript? | |
-- | |
-- ------------------------------------------------------------ | |
-- TO DO | |
-- * pull html TITLE tag of page, place it as bash comment in dumpfile | |
-- * check to see if Chrome is even running, do nothing otherwise | |
-- * pass paramter from cmd line to script for description comment in bash file | |
-- (apparently this is going to be hard…) | |
-- | |
-- x automatically save the file, do not throw dialog | |
-- ------------------------------------------------------------ | |
-- setup variables | |
-- set defaultFolder to POSIX file myDumpLocation | |
set myDate to do shell script "date +%Y-%m-%d-%Hh%Mm" | |
set myTabFile to myDate & "-tabset" | |
set myDumpLocation to "/Users/tcyun/Downloads/" & myTabFile | |
-- make sure that you have a sane default folder, otherwise dump to desktop | |
-- note, putting a bad path in the variable above will make this check | |
-- fail. unclear why this happens... | |
-- | |
-- ahh, i see i am testing folder against a file | |
-- keeping this here as i should fix it later | |
-- try | |
-- set defaultFolder to POSIX file myDumpLocation | |
--on error | |
-- set defaultFolder to (path to desktop) | |
--end try | |
-- Initialize the text ot the script. | |
set cmd to "#!/bin/bash" & linefeed | |
set cmd to cmd & "# " & linefeed | |
set cmd to cmd & "# " & myDate & linefeed | |
set cmd to cmd & "# " & linefeed | |
set cmd to cmd & linefeed | |
-- set cmd to cmd & "open ~/tcy-script/MacOS-stuff/tabSets/forceIncognito.app/" & linefeed | |
-- the above line forces a new incognito window to open and then dumps the files into that window | |
set cmd to cmd & linefeed | |
-- grab URL for each tab in the front window | |
tell application "System Events" to tell process "google chrome" | |
activate | |
tell application "Google Chrome" | |
set n to count of tabs in front window | |
repeat with i from 1 to n | |
-- need to write a catch that eliminates empty tabs/blank urls | |
set urlstring to "" | |
set urlstring to URL of tab i of front window | |
set urlstring to quoted form of urlstring | |
-- the quoted form here is important for weird URLs | |
set cmd to cmd & "open -g -a /Applications/Google\\ Chrome.app/ " & urlstring & " --args --incognito " & linefeed | |
end repeat | |
-- if you want, you can have the script close the window | |
-- close front window | |
end tell | |
end tell | |
-- Open/create a file and save the script. | |
-- --use this if you want to name the file manually | |
--set scriptAlias to choose file name default name myTabFile default location (defaultFolder as alias) | |
--set scriptPath to POSIX path of scriptAlias | |
--set scriptFile to open for access scriptAlias with write permission | |
--set eof scriptFile to 0 | |
--write cmd to scriptFile starting at eof | |
--close access scriptFile | |
-- automatically write to file | |
do shell script "echo " & quoted form of cmd & " >" & myDumpLocation | |
-- Change the file attributes to make it double-clickable. | |
do shell script "chmod 777 " & myDumpLocation | |
do shell script "xattr -wx com.apple.FinderInfo '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00' " & myDumpLocation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment