This guide contains instructions to set up an iPhone widget which will show the train arrivals at a Washington Metropolitan Area Transit Authority (WMATA) metro station of your choosing (line color, destination, and minutes until arrival). The widget pulls this information from WMATA's API, so it’s real-time. The datetime stamp in the bottom right corner shows when the widget was last updated, and the line above it shows the station’s name (so you don’t mix them up in case you want to have multiple widgets).
The widget looks like this:
I adapted the code for this from the Python version here (the version I made is in JavaScript).
I wrote this for train stations and to show the next five arrivals (though the widget will show fewer than five if there are fewer than five trains on the way).
This guide assumes you’ll follow the steps below from your iPhone itself.
-
Download the Scriptable app from the app store.
-
Open the script template in the Scriptable app:
- From your iPhone, go to the file 2 WMATA ifelse w loc - share.js.
- Select all the text and copy it to your clipboard.
- Create a new script in the Scriptable app and paste the code inside it.
-
Go to this GitHub repo, and use that information to edit the “LIST OF DICTIONARIES FOR UPCOMING ARRIVALS” section of the script (it starts at line five):
- On line 6, replace “x” with the code for your metro stop (see the appendix of that GitHub website).
- On line 7, replace “STOP NAME HERE” with the name of the metro stop corresponding with the code you use to replace “x.”
- On line 8, replace “y” with your WMATA API key (see Part Three of that GitHub website).
-
Add the widget to your home screen:
- Touch and hold to make the apps wobbly (as if you were going to rearrange them).
- Click the plus icon in the top left corner, search for Scriptable, select the widget size you would like (I like the medium-sized one as pictured above), and select the name of the WMATA arrivals widget. Set “When Interacting” to “Run Script.”
-
To use the widget, click on it on your home screen; this will open the Scriptable app and refresh the widget. Go back to your home screen to look at the updated arrival times. The time you last updated the widget will be in the bottom right corner.
- The widget should update itself automatically one time every morning or so. Other updates are up to you.
