Skip to content

Instantly share code, notes, and snippets.

@wearhere
wearhere / keep_current_file_open.sh
Created February 9, 2012 09:34
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 http://stackoverflow.com/questions/7682277/xcode-4-2-jumps-to-main-m-every-time-after-stopping-simulator
@wearhere
wearhere / toggle_uiautomation_views.scpt
Created February 10, 2012 10:52
Toggle Between Script and Editor Log Views in UIAutomation Instrument
(*
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 February 20, 2012 04:16
Clear Xcode Console from the Simulator
# 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 04:48
Checkout previous Git branch
#!/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 August 29, 2012 00:33
Boolean literals are only sometimes of type BOOL.
- (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 December 18, 2015 08:29
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
SLAlert *buyAlert = [SLAlert alertWithTitle:@"Confirm Your In-App Purchase"];
SLAlertHandler *buyHandler = [buyAlert dismissWithButtonTitled:@"Buy"];
[SLAlertHandler addHandler:buyHandler];
@wearhere
wearhere / gist:5754930
Last active December 18, 2015 08:29
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
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 December 18, 2015 08:29
Identify a button labeled "$1.99" using UIAutomation directly. Contrast https://gist.github.com/wearhere/5754942. http://inkling.github.io/Subliminal
var button = target.frontMostApp().mainWindow().tableViews()[1].buttons()["$1.99"];
@wearhere
wearhere / gist:5754942
Last active December 18, 2015 08:29
Identify a button labeled "$1.99" using Subliminal. Contrast https://gist.github.com/wearhere/5754939. http://inkling.github.io/Subliminal
SLButton *buyButton = [SLButton elementWithAccessibilityLabel:@"$1.99"];
@wearhere
wearhere / gist:5754948
Last active December 18, 2015 08:29
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
[[SLTestController sharedTestController] registerTarget:[DownloadManager sharedManager] forAction:@selector(downloadBookWithId:)];