Skip to content

Instantly share code, notes, and snippets.

@wearhere
wearhere / keep_current_file_open.sh
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)
View keep_current_file_open.sh
#! /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 http://stackoverflow.com/questions/7682277/xcode-4-2-jumps-to-main-m-every-time-after-stopping-simulator
@wearhere
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
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
wearhere / checkout_previous_branch.sh
Created May 19, 2012
Checkout previous Git branch
View checkout_previous_branch.sh
#!/bin/sh
## 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 ]
then
echo "No previous branch has been recorded. You're probably not using the post-checkout hook."
exit 1
@wearhere
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
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: https://gist.github.com/wearhere/5754930. http://inkling.github.io/Subliminal
View gist:5754912
SLAlert *buyAlert = [SLAlert alertWithTitle:@"Confirm Your In-App Purchase"];
SLAlertHandler *buyHandler = [buyAlert dismissWithButtonTitled:@"Buy"];
[SLAlertHandler addHandler:buyHandler];
@wearhere
wearhere / gist:5754930
Last active Dec 18, 2015
The JavaScript generated by Subliminal (here: https://gist.github.com/wearhere/5754912) to dismiss an in-app purchase alert by tapping "Buy." http://inkling.github.io/Subliminal
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
alert.buttons()['Buy'].tap();
}
}
@wearhere
wearhere / gist:5754939
Last active Dec 18, 2015
Identify a button labeled "$1.99" using UIAutomation directly. Contrast https://gist.github.com/wearhere/5754942. http://inkling.github.io/Subliminal
View gist:5754939
var button = target.frontMostApp().mainWindow().tableViews()[1].buttons()["$1.99"];
@wearhere
wearhere / gist:5754942
Last active Dec 18, 2015
Identify a button labeled "$1.99" using Subliminal. Contrast https://gist.github.com/wearhere/5754939. http://inkling.github.io/Subliminal
View gist:5754942
SLButton *buyButton = [SLButton elementWithAccessibilityLabel:@"$1.99"];
@wearhere
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: https://gist.github.com/wearhere/5754953. http://inkling.github.io/Subliminal
View gist:5754948
[[SLTestController sharedTestController] registerTarget:[DownloadManager sharedManager] forAction:@selector(downloadBookWithId:)];