

We create a second identical applescript with only the option 1 instead of 0 for the python script (I’m sure there’s a better way of doing this, but that’s enough for me for the moment). For more instructions on how to create the applescript service with Automator check this previous blog entry.ĭo script “gotopy python print_url.py 0 exit” in window 1 The command gotopy here is just my alias to cd into the right folder. Two things to note here, one is to call the script in window 1 otherwise it will open two instances of the terminal and the second one is the “if not (exists window1) then reopen” which makes sure that we can open a terminal whether the application is already opened or not. The second step needed is to create two Applescript that call the terminal application and launch the python script. In the second case (calling the function with 1), I load the temp file with all the urls and using the webbrowser module, I open all the saved URLs back in new tabs. In one case (calling the function with 0), I grab the content of the clipboard with Tkinter and save it to a temp file on the Desktop. Here I used the clue from PyDanny’s blog to create a switch for the options of the argument of my function/script. # Get the function from switcher dictionaryįunc = switcher.get(argument, lambda: “nothing”) Text_file.write(“%s” % text_in_clipboard) Root.withdraw() # Hide the main window (optional) This send the URL of all the open tabs to the clipboard, so that it can be easily grabbed in python and saved to a txt file. I’m sure it could be done with a bit of tinkering in Applescript (or shell script, but that would be out of my league), but for now let’s appreciate the work of the creator of CopyAllURLs for Google Chrome. After spending enough time looking and getting confused, I settled on the easiest and most practical solution, use somebody else’s work. Terrible idea.įirst I tried to find a way to grab the URLs from the open Chrome browser via python, but ignorant me, I couldn’t find them. Up until now I stupidly copied them by hand to some file and them reloaded them by hand again. Okay I sometimes have tens of open URLs on my Chrome and I don’t want to lose.
