3 min read

Threaded tweeting from Keynote for conference talks using #rtweet

Threaded tweeting from Keynote for conference talks using #rtweet

I have been using Keynote Tweet, an app maintained by Alan Levin for several years now to send automated tweets during conference presentations.

Most journalism conferences have active backchannel discussions (almost all on Twitter) so it is like magic to drop links and footnotes into that discussion while on-stage presenting.

Keynote Tweet uses AppleScript to pull text from your presenter’s notes on each slide, and sends the updates to the internet using Twurl.

I pulled out the app last month for an event at the New York Press Association and after sending 40 updates realized that, as built, it does not support tweet threading. So each of my updates was a separate object, making it difficult for people to follow.

Luckily, my office at the Missouri School of Journalism is next to Dr. Mike Kearney, the developer of rtweet, a fantastic tool for analyzing and working with Twitter.

So, after just a bit of work and much Googling, I adapted Keynote Tweet to support rtweet with threaded replies.

https://twitter.com/dkiesow/status/1122187259439190016
Example of my first test thread on Twitter.

I will eventually get this documented more carefully but for now, some brief instructions and the updated code are below. Apologies but these are Mac-centric (after all it is Keynote-based) and the entire thing has only been tested on OS 10.14.

Requirements
R for Mac OS X
R Studio
Rtweet
Twitter developer account and app
Script Editor, Terminal, Keynote — on your Mac
keynote.R — R script provided below
Keynote rTweet — AppleScript provided below

You will need to know how to get R and rtweet installed correctly — it is not enormously difficult and the links above provide details.

Once both are installed, the basic directions from Mike to set up rtweet to access your Twitter account are:

1.Create an app in Twitter
To gain access Twitter’s APIs, first go to apps.twitter.com and create a new app by completing the form fields. Approvals may take a day or two.

(note: you must enter the value for Callback URL exactly as it appears below.)

Name: Name of Twitter app e.g., my_keynote_app 
Description: Describe use case e.g., for tweeting from Keynote
Website: A valid website e.g., https://twitter.com/kearneymw
Callback URL: http://127.0.0.1:1410

Check yes if you agree and then click “Create your Twitter application”

2. Set the access token:
In R Studio — create a new session and from the command line create a token and save it as an environment variable by copy/pasting the below — using your own keys — the ones below are fake.https://medium.com/media/1c8186363ea3324ab4c32a055276b4c8

And that’s it!

In R Studio, create a new file and copy/paste the following code. Name it keynote.R and save it somewhere convenient and permanent. You should not need to modify the code. (View raw to copy)

#!/usr/bin/env Rscript
##keynote.R v1.1 Damon Kiesow @dkiesow
##Use with the Keynote rTweet AppleScript app to automate threaded tweeting during Keynote presentations
##
## load rtweet package
library(rtweet)
me <- rtweet:::home_user()
## Pull parameters from command line (first_status will be "yes" or "no" and provided from the AppleScript)
args <- commandArgs(trailingOnly = TRUE)
## Check to make sure there are two parameters
if (length(args) < 2) {
stop("Two arguments must be supplied")
} else if (length(args) == 2) {
keynote_status <- args[1]
first_status <- args[2]
}
##From version 1.0 added these two lines to fix a character encoding issue with curly quotes in the tweets.
keynote_status = iconv(keynote_status, "UTF-8", "cp1252");
keynote_status = gsub("(\x93|\x94)", "\"", keynote_status, perl = T)
keynote_status = gsub("(\x92)", "'", keynote_status, perl = T)
## Send a new tweet if first_status is "Yes" and reply tweet if "No"
## If you neglect to set the "[first]" flag in Keynote it will thread from your most recent tweet
## rtweet uses "get_timeline" to pull the last 3 tweets from your account
## It then uses "reply_id" to pull your last tweet's "status_id" from the data table of "my_timeline"
if (first_status == 'yes') {
post_tweet(status = keynote_status)
} else {
my_timeline <- get_timeline(user = me, 3)
reply_id <- my_timeline[1, 2]
post_tweet(status = keynote_status, in_reply_to_status_id = reply_id)
}
view raw keynote.R hosted with ❤ by GitHub

Find Script Editor on your Mac and create a new file. Copy/paste this code:

global extras
global lastTweet
property okflag : false
-- Keynote rTweet 1.0 Damon Kiesow @dkiesow
-- Entirely adapted for rtweet from Keynote-Tweet maintained by Alan Levin @cogdog
-- https://github.com/cogdog/Keynote-Tweet
-- This version requires rtweet from @kearneymw
-- https://rtweet.info/index.html
set dialogResult to display dialog ¬
"Version 1.0 by @dkiesow... Would you like to add any text (e.g. #hashtags or @usernames) to all of your tweets?" with title ¬
"Keynote-rTweet" with icon note ¬
default answer ¬
"" buttons {"None", "Add This Text"} ¬
default button "Add This Text"
if button returned of dialogResult is "None" then
set extras to ""
else
set extras to text returned of dialogResult
end if
set lastTweet to ""
display dialog ¬
"The app will tweet everything between the [twitter][/twitter] tags in your presenter notes when you advance pages in Keynote. For your first tweet - put [first] after the closing [/twitter] Use the menu to quit this script when you're finished." with title ¬
"Keynote TweetR" with icon caution ¬
buttons {"Begin"} ¬
default button "Begin"
on idle
tell application "System Events"
set okflag to (exists (some process whose name is "Keynote"))
end tell
if okflag then
tell application "Keynote"
if playing is true then
set slideNotes to get presenter notes of current slide of first document
if slideNotes is not equal to "" then
set leftCoord to offset of "[twitter]" in slideNotes
set rightCoord to offset of "[/twitter]" in slideNotes
set first_check to offset of "[first]" in slideNotes
log first_check
if first_check is greater than 0 then
set firstTweet to "yes"
log firstTweet
else
set firstTweet to "no"
log firstTweet
end if
if leftCoord is greater than 0 and rightCoord is greater than 0 then
set tweet to get characters (leftCoord + 9) thru (rightCoord - 1) of slideNotes as string
if tweet is not equal to "" then
if extras is not equal to "" then set tweet to tweet & " " & extras
if tweet is not equal to lastTweet then
set twitter_status to quoted form of (tweet)
-- Replace the below with the appropriate paths for your system (rscript path and then the path to your R script)
do shell script "/usr/local/bin/rscript /Users/kiesowd/keynote_tweet/keynote.R " & twitter_status & " " & firstTweet
log twitter_status
log firstTweet
set lastTweet to tweet
end if
end if
end if
end if
end if
return 1
end tell
end if
end idle

In this code (on line 59) you will need to change the path to ‘rscript’ and the path to the keynote.R file that you created.

Compile the script (the hammer icon at top of the Script Editor window) and then export that file as an application and click ‘stay open after run handler’

Exporting from Script Editor

Name it anything convenient like Keynote rTweet and save it somewhere easy like ‘Applications.’ This is the part of the app you will actually need access to on a regular basis.

Open up Keynote and create a title slide. Then create a content slide, select ‘show presenter’s notes’ and enter:

[twitter]Test of Keynote rTweet[/twitter][first]

The “[first]” at the end is important so the app knows to start a new thread.

Create a third slide and enter:

[twitter]Keynote rTweet with threaded replies works[/twitter]

Find the Keynote rTweet AppleScript App and run it. It will show some instructions and ask if you want to use a hashtag. On the initial run it will also ask permission to control Keynote — say “yes.”

Switch back to Keynote and run the presentation. The script picks up the status text when you change slides.

Page through your three slides and then check Twitter. If everything worked, you should see the updates. If not, you may need to dig into some of the details provided at the links above. But trust me that it does work and it is worth some effort to get it running on your Mac.

Happy tweeting.

Also published on Medium