Geektool Scripts For Word

Jul 02, 2017 šŸ”„ GeekTool Scripts šŸ”„. Here is a collection of scripts that I use with GeekTool. Some need to be update to be less. Tied to my desktop. This script is for running AppleScripts from the shell. It expects the AppleScript to be in the same directory as it, and it takes the script as a command line parameter. No external script paths, just simple shell commands. I have an air, 10.6.6 and geektool v3 runs horrendously slow. It can take 5 minutes to properly place a window. Just clicking on it in the menu bar takes 3 seconds to pop up. Typing in the size box for example can take 30 seconds. Anyone else having serious lag using it with v3 after adding. Geektool scripts that I made myself: ā€“ itunes current track. ā€“ new mail message. ā€“ IP- number with location. ā€“ Airport status if connected then name of connected wireless network will be displayed. And an image that will indicate the signal strength. ā€“ weather script (just the conditions no images here).

Adding Twitter into GeekTool using OAuth!

Iā€™ve been playing around with GeekTool recently and one of the first things I wanted to include was my Twitter timeline on my desktop which proved to be a more difficult task than I expected..

The main issue was any existing Twitter GeekTool scripts I found used basic authentication which is no longer supported by the Twitter API as it was replaced with OAuth authentication (which is good, but makes accessing the API authenticated a bit more difficult).

I wasnā€™t having much luck until I started searching for a command line Twitter access using OAuthā€¦ then I stumbled on a blog post containing a Python script which could retrieve user timelines, post tweets etc. designed to run using OAuth.

It worked fine out the box, but after a bit of manual configuration, I started adding some pretty formatting then found myself adding some new features like a Twitter search or retweet monitoring etcā€¦.

I then integrated the OAuth app/token creation, while trying to make it as user-friendly as possible, limiting the amount of prerequisites to run this script to a minimum. Iā€™ve tested this script using the latest version of GeekTool (available in the Mac App Store) using OSX Lion, It should workā€¦ but as a disclaimer Iā€™m throwing this up as a ā€˜work in progressā€™ script, but should get the job done.

It has come to my attention: That GeekTool sometimes will not see the full path to python2.7, I believe it was working on my system because I have Xcode installed. I have amended the script to print an example line using full paths for GeekTool, but can only test this on my system. (which appears to work.)

Geektool Scripts For Word Processor

STEP 1:

Well python comes pre-installed on OSX so you shouldnā€™t need to install anything new, but we do need to get the 'Tweepyā€™ package to talk to the Twitter API.

The easiest way I found to install this was via the terminal using the following command:

This works but only seems to apply to python2.7 if I cared enough I would maybe try to work it out for the default version of python (2.5) but the path of least resistance means that to run the script we are just going to use python2.7 to execute it. :/

Update: In recent updates I have made the script compatible with Python2.5 -> Python2.7, Iā€™ve documented my experience in installing the required packages on my GitHub Wiki.

STEP 2:

Download the script (now from GitHub) extract it and place the script somewhere safe so it doesnā€™t get moved etc. The file may not be executable with the default permissions.. so via command line run the following command:

Update: If you download the package from GitHub it should have the correct permissions so you can most likely ignore this step.

STEP 3:

Geektool Scripts For Word

Next run the script using the python version that is set up with Tweepy via the terminal, On first run it will help you setup a OAuth application allowing you to connect to the Twitter API authenticated. Iā€™ve tried to make this as easy as possible. Iā€™ve added the -a option to the command but technically you shouldnā€™t need to add it unless you want to reset your OAuth authentication file.

or

or

Pretty much you go to the Twitter dev site and create an application then enter your ā€™Consumer Keyā€™ and ā€™Consumer Secretā€™ when prompted.

This will then attempt to generate your 'Accessā€™ tokens asking you to go to an Authorisation URL giving you a PIN number to enter.

Hopefully you should have no issues, enter the PIN code that is generated, then your OAuth access authentication tokens will be created and saved to the configuration file. This will allow you to run the script and pull down your Twitter timelines using your OAuth authentication tokens.

Update: After the OAuth setup is complete, it will display the full path of python and the currently location of the script. (If you have trouble adding this GeekTool this example line should work..)

Step 4:

You should be able to test if it has worked by running the command line:

or

or

It will hopefully have displayed your latest 30 tweets in your timeline, hopefully by now you have guessed this is the type of shell command you would configure into GeekTool but making sure to add the full path to the script.

Here is a screenshot of my desktop using GeekTool and the -rtm command, Iā€™m assuming because these are retweets, they are public accounts and/or the information displayed in this screenshot is publicā€¦ :/

Adding Script into GeekTool:

GeekTool runs all scripts from the root directory so when you add the Twitter script into GeekTool you will need to use the full path to the script for it to run properly. Using the command line type in the command:

pwd

This will give you an output of your current working directory, the default output should be /Users/<username> but for completeness you should run the command to be absolutely sure. You can run the script from anywhere on your computer but I believe best practice is to create a new folder to store all your GeekTool scripts in (so you donā€™t delete or move the file/folder accidentally.) A few examples of different places to create your GeekTool scripts folder:

Next you need to open the GeekTool preferences and drag a 'Shellā€™ module to the desktop. These are the settings that I use:

Name: Twitter Feed Command: python2.7 /Users/<username>/geektool-scripts/twittercli.py -t -c30*You may need to put the full path to python* Refresh every: 300 (seconds) Font: Menlo (size 10) Alignment: Left

This should get you started, Iā€™ve added a few other features like showing mentions and retweets etc. I havenā€™t documented fully but info for these in a options is available running the ā€™ā€“helpā€™ option.

NOTES:

  • You should add an generous refresh time in GeekTool to prevent being rate limited by the Twitter API. (I use 5 minutes)
  • The formatting only works properly with a monospace font.. (I use Menlo)
  • Some fonts if they are too small the bolding doesnā€™t workā€¦ :/
  • For the Twitter search option use quotes, otherwise it will only work for one word, and if that one word starts with a hash (#) python and/or bash will ignore it.. :/
  • I realise my code is a bit dodgy consider this an Alpha releaseā€¦
  • Script is somewhat work in progress/beta.

Finally:

So hopefully, this post should at least get you on the right track. Iā€™m planning to do some updates/streamline the process, any feedback is welcomeā€¦

Incase you missed it, the script file is here: https://github.com/gmanual/Twitter-OAuth-GeekTool-Script

Update:

Geektool Scripts For Word Download

  • Updated script to Version 0.1, better argument handling using ā€™argparseā€™, I believe this means this script now 100% requires python2.7 but pushing ahead, search is broken until I fix, but pushing update because I think this is an important update.
  • Updated script to Version 0.2, fixed search and implemented custom number of results (default is 30)
  • Updated script to Version 0.3, code optimisation/restructure, Iā€™m a lot happier with this code than the orignal.
  • Updated script to Version 0.4, implemented a change/feature: If script is run and no auth details are found it will prompt to run OAuth setup, if OAuth settings are detected it will display by default your home timeline.
  • Updated script to Version 0.5, fixed potential bug in determining config file location, going though supported Twitter API commands and adding them one by one. Latest public tweets added in this version. I am also looking at implementing some form of caching.
  • Updated script to Version 0.6, code optimisation/restructure, checks if you can connect to the Twitter API, if it can not it will print a nice message. (Sanity checking for if you are offline.) No caching yet.
  • Updated script to Version 0.7, fixed OAuth setup bug (not really a bug but kinda was), also added direct messages support. You will need to enable extra permissions on your Twitter App to view direct messages.
  • Updated script to Version 0.8, added -e option to show an example GeekTool command pulling full paths for both python2.7 and your script location. (This should help if you donā€™t know much about scripting etc.) Note: This was a quick hack while Iā€™m out-of-town, I will look into better ways of performing this once Iā€™m home.
  • Updated script to Version 0.9, added -n option to add spacing between tweet output.
  • Updated script to Version 1.0, no functionality added but code is now commented. I had always planned if I made it to Version 1.0 I would add a code project page which has now been done on GitHub.

Another Update:

Iā€™ve added this script to a GitHub open source project found here: Twitter-OAuth-GeekTool-Script

All issues should be reported here or if you want to watch the project to get updates this is probably the best place to do so.

Update (March 18, 2019): As of Thursday, Jan. 3, 2019, the weather.yahooapis.com and query.yahooapis.com for Yahoo Weather API are retired. New APIs using OAuth1 are now available. Details here. Version 2.0 incorporating OAuth1 and switching to JSON for retrieval can be found here.

Update (May 7, 2016): Many thanks to kind reader @chogc who asked about the metric option to display temperature in Celsius. That feature has been corrected. I also implemented a workaround of a Yahoo! weather bug in which the sunset time string drops the leading zero for the minutes in some locations. Version 1.1 incorporating these fixes can be found here.

Iā€™m a long-time GeekTool user, which I use to display various pieces of information on my Mac desktop. One of my favorite displays is current weather information. A few years ago after browsing on the Internet for various weather geeklets and scripts, I settled on one created by Thomas Upton written in Python that used Yahoo! weather for displaying current conditions, called weather.py:

I also used two additional scripts from other sources for displaying a current weather image icon obtained from Yahoo! and another that displayed a five-day weather forecast.

Over the years, problems arose with the current weather image icon script that required various workarounds, such as switching to the French Yahoo! weather site for images.

A few months ago, all three weather scripts stopped working. I searched around for answers, which led me to various theories (see here and here) as to why the scripts no longer worked. Ultimately, the problem was due to a query change instituted by Yahoo! in its public API for retrieving weather conditions and forecasts.

I thought about patching the various scripts. Instead, I chose to base a consolidated solution for displaying a weather icon, current weather conditions, and forecast upon Thomas Uptonā€™s original Python script, which I called weather-new.py, partnered with a custom Bash script called weather-condition.sh for assisting with the current weather icon handling.

Geektool Scripts For Word

The changes I made to the original Python script were four-fold:

  • First, I modified the query request to Yahoo! Weather to use the new format request (more about that shortly);
  • Second, I added output of a short weather description so that I could build a Bash ā€œwrapperā€ script to select a corresponding weather image from a collection of icon files for display purposes;
  • Third, I added day-night awareness to permit selection of day-night-dependent weather icons; and
  • Fourth, I added the optional display of the sunrise and sunset times and a few other weather options such as wind chill (also known as the ā€œfeels-likeā€ temperature).

Using the Yahoo! Weather Developer documentation, I added the additional data structures to the Python script needed to obtain the additional weather information, and I also added a few new runtime options for requesting the sunrise/sunset times, determining whether it is currently day or night, returning the weather code defined in the Yahoo! Weather Developer documentation, returning the last update time for the current weather conditions, and returning the wind chill.

I also used the query change information described here to alter how the script fetched weather information from Yahoo! One of the other consequences of the query change required a switch from using ZIP Codes to using WOEID (ā€œWhere On Earth IDā€) as a location identifier. For example, queries that used to look simple like this:

changed into more complex queries that looked like this:

After making the query change to the Python script (and finding my WOEID, which I did here), collecting a set of weather icons that I liked, and creating a new Bash wrapper script for handling weather images, the results on my desktop look like this:

Iā€™m rather pleased with the result.

If youā€™re a GeekTool user, here is how I constructed the above, with each rounded rectangle representing a different geeklet in GeekTool:

  • ~/Applications/weather-condition.sh is a Bash script that calls Yahoo! weather via the weather-new.py Python script to obtain the short description of the current weather condition. Based on that description, the Bash shell copies the associated weather icon file to the location /tmp/weather.png.
  • file:///tmp/weather.png shows the result of the ~/Applications/weather-condition.sh Bash script
  • ~/Applications/weather-new.py ā€“lvrs 12791684 calls Yahoo! weather and displays the location, sunrise, sunset, and current conditions in verbose mode for WOEID 12791684 (which is my location).
  • ~/Applications/weather-new.py ā€“-nocurr ā€“f5 12791684 calls Yahoo! weather and displays a five-day forecast for my location without displaying the current weather status; echo Five day forecast: is for display purposes.

Geektool Scripts For Word Problems

Iā€™ve put the weather-new.py Python script, weather-condition.sh Bash script, and a set of weather icons into a zip archive, which you can grab here. I also put the geeklets in the archive for your use if youā€™re a GeekTool user. Just double-click the geeklets to install them into GeekTool, and customize the geeklets based on your WOEID and where you placed the scripts and weather icon folder. I placed mine in ~/Applications (the Applications folder inside my home folder, not the main Applications folder where applications are kept). If you place the scripts and weather icon folder into an alternative location, also make the corresponding location mods to the weather-condition.sh script.

Enjoy!