Skip to content

Instantly share code, notes, and snippets.

wearhere /
Created Feb 9, 2012
Keep your current source file open in Xcode after a run completes (a.k.a don't die in main.m)
#! /bin/sh
# On alternate invocations, this script
# saves the path of the source file currently open in Xcode
# and restores the file at that path in Xcode.
# By setting Xcode (in Behaviors) to run this script when "Run Starts"
# and when "Run Completes", you can prevent it from switching to main.m
# when a run finishes.
# See
wearhere / toggle_uiautomation_views.scpt
Created Feb 10, 2012
Toggle Between Script and Editor Log Views in UIAutomation Instrument
View toggle_uiautomation_views.scpt
Running this script will cause Instruments to become active
and switch from the Script view (where you edit your UIAutomation script)
to the Editor Log view (where you see the logs of executing those scripts)
or vice versa.
-- JW: This block only needs to be executed once, and can then be removed.
-- I don't know if leaving it in might cause a performance hit;
wearhere / clear_xcode_console.scpt
Created Feb 20, 2012
Clear Xcode Console from the Simulator
View clear_xcode_console.scpt
# Clears Xcode's console,
# then switches back to the iOS Simulator.
activate application "Xcode"
tell application "System Events"
tell process "Xcode"
click menu item "Clear Console" of menu 1 of menu item "Debug" of menu 1 of menu bar item "Product" of menu bar 1
end tell
end tell
activate application "iPhone Simulator"
wearhere /
Created May 19, 2012
Checkout previous Git branch
## Checks out the branch with the name recorded in the .PREVIOUS_BRANCH file
## in the working directory. To use this script, you should be using the
## post-checkout hook that creates such a file.
if [ ! -f ./.PREVIOUS_BRANCH ]
echo "No previous branch has been recorded. You're probably not using the post-checkout hook."
exit 1
wearhere / whatsabool.m
Created Aug 29, 2012
Boolean literals are only sometimes of type BOOL.
View whatsabool.m
- (void)testBooleanLiteralsAreOfTypeBool {
NSNumber *testBoolNumber = @YES;
const char *typeString = [testBoolNumber objCType];
STAssertTrue('c' == *typeString, @"Boxed BOOL is of type %s, not of type 'c' (signed char, aka BOOL).", typeString);
- (void)testBoxedBooleanLiteralsAreOfTypeBool {
// Boxing works fine if a BOOL value is boxed directly...
BOOL testBool = YES;
NSNumber *testBoolNumber = @(testBool);
wearhere / gist:5754912
Last active Dec 18, 2015
Dismiss an in-app purchase alert by tapping "Buy," using Subliminal. Subliminal then generates the JavaScript shown here:
View gist:5754912
SLAlert *buyAlert = [SLAlert alertWithTitle:@"Confirm Your In-App Purchase"];
SLAlertHandler *buyHandler = [buyAlert dismissWithButtonTitled:@"Buy"];
[SLAlertHandler addHandler:buyHandler];
wearhere / gist:5754930
Last active Dec 18, 2015
The JavaScript generated by Subliminal (here: to dismiss an in-app purchase alert by tapping "Buy."
View gist:5754930
UIATarget.onAlert = function(alert) {
// if the alert has the expected title
if (alert.staticTexts()[0].label() === "Confirm Your In-App Purchase") {
// tap the button
wearhere / gist:5754939
Last active Dec 18, 2015
Identify a button labeled "$1.99" using UIAutomation directly. Contrast
View gist:5754939
var button = target.frontMostApp().mainWindow().tableViews()[1].buttons()["$1.99"];
wearhere / gist:5754942
Last active Dec 18, 2015
Identify a button labeled "$1.99" using Subliminal. Contrast
View gist:5754942
SLButton *buyButton = [SLButton elementWithAccessibilityLabel:@"$1.99"];
wearhere / gist:5754948
Last active Dec 18, 2015
Register a "download manager" for an app hook that downloads a book. Then call that hook here:
View gist:5754948
[[SLTestController sharedTestController] registerTarget:[DownloadManager sharedManager] forAction:@selector(downloadBookWithId:)];