Delete App on Simulator through Command Line - xcode

Im writing an automated test that will use the Instruments automator to run a series of UX tests on my application. The problem is, I need the app to run on a fresh install for the specific set of tests that I am running. Is there a way to delete an app in the simulator through the command line?
Specifically, I am looking for something like this:
xcodeBuild -delete myApp.app

Something like this might work, although I haven't fully tested it:
rm -rf ~/Library/Application\ Support/iPhone\ Simulator/6.0/Applications/*
Substitute the proper simulator version number for the 6.0 of course.

I actually ended up using the solution found here: https://stackoverflow.com/a/5128616/608739
The apple script works great and gets around all those pesky simulator issues.
--------------- OLD POST -------------------
Using jpancoast's lead, I modified his script to find and clear the latest version of the app on simulator:
CURRENT_SDK=""
if [ -z "$RUN_ON_SPECIFIC_DEVICE_OPTION" ] ; then
CURRENT_SDK=$(xcodebuild -showsdks | grep 'iphoneos[0-9].[0-9]' | grep -o '[0-9].[0-9]' | head -n1)
else
CURRENT_SDK=$(xcodebuild -showsdks | grep 'iphonesimulator[0-9].[0-9]' | grep -o '[0-9].[0-9]' | head -n1)
fi
rm -rf ~/Library/Application\ Support/iPhone\ Simulator/"$CURRENT_SDK"/Applications/*
The script checks to see if we are currently running on device or not. It then finds the folder corresponding to the latest SDK (assuming your project is building on that SDK) and deletes all applications associated with that SDK version. Further refinement can be made to only delete specific apps you are interested in.

Assuming you know the iOS version and the name of the app, this is a script I put together to remove a single app. It comes in handy if you don't want to reset the entire simulator and lose all other installed apps.
The script below is part of a larger script I use, but should work as shown. I've got this saved as simulator-uninstall.sh, you can then uninstall an app using something like:
./simulator-uninstall.sh ios=7.1 app="My App"
Here's the script (note, bash is not my strong point, but this worked for me!):
#!/bin/bash
for p in "$#"; do
# Parse out each param which needs to be of the form key=value
# Then remove any quotes around the value, because we will quote all vars anyway
IFS="=" read argkey argvalue <<< "$p"
argvalue="${argvalue%\"}"
argvalue="${argvalue#\"}"
case $argkey in
ios) IOS_VERSION=$argvalue
;;
app) APP_NAME=$argvalue
;;
esac
done
SIMULATOR_ROOT="$HOME/Library/Application Support/iPhone Simulator/$IOS_VERSION"
# Find the *.app directory
APP_PATH=`find "$SIMULATOR_ROOT/Applications" -name "$APP_NAME.app"`
if [ "$APP_PATH" ]; then
# Ensure simulator isn't running whilst we remove the app
killall "iPhone Simulator"
# Get the parent directory - this will be a UUID, then remove it
APP_DIR=`dirname "$APP_PATH"`
rm -rf "$APP_DIR"
echo "Removed $APP_DIR"
else
echo "App $APP_NAME not found for platform version $IOS_VERSION"
fi
Hope that helps!

Related

Rename/translate multiple files on Mac

I have a lot of files with names in one language and I need to rename them all to another one.
Is there any script for this? (preferably on Mac)
Figured it out. We can do it with translate-shell CLI utility.
Install it with brew install translate-shell
Then run next script in your folder:
for i in *.txt
do
sleep 5
mv -i "$i" "$(echo ${i%.txt} | trans -b nl:en).txt";
done
translate-shell makes a call to Google Translate server to do translation
sleep 5 is needed to avoid being blocked by Google's server for too many requests in a second
trans is actual translate command
-b stands for "brief", as we don't need verbose output
nl:en are the source and destination languages

How to use opendiff and git diff and not needing to install the whole Xcode app?

After upgrading to MacOS Mojave, my git and opendiff stopped working (my opendiff is usually invoked by git diff).
I was able to get git working, by using the following two lines:
xcode-select --install
sudo xcode-select -switch /Library/Developer/CommandLineTools
but opendiff and git diff still doesn't work. It seems one solution is to install the Xcode app, which is huge (said to be taking up 10GB on the hard drive). I checked Spotlight and typed FileMerge, and was able to find it, which should be the same as opendiff, and was able to use ps ax to find the path /Applications/Xcode.app/Contents/Applications/FileMerge.app/Contents/MacOS/FileMerge. But then, using git diff, I actually used a bash script to invoke
#!/bin/sh
/usr/bin/opendiff "$2" "$5" -merge "$1" | cat
(see this github article about how to set up git-diff-cmd.sh)
so I changed that second line to:
/Applications/Xcode.app/Contents/Applications/FileMerge.app/Contents/MacOS/FileMerge "$2" "$5" -merge "$1" | cat
but it doesn't work. So FileMerge exists, and it looks like opendiff is FileMerge. Can git diff be made to work without needing to install the whole Xcode app?
This may seem like a hack, and in fact it seems like it is using an existing installation of XCode:
I did
cd /Applications/Xcode.app
find . -iname '*opendiff*'
and was able to find
./Contents/Developer/usr/bin/opendiff
./Contents/Developer/usr/libexec/git-core/mergetools/opendiff
The first file is a binary file, and the second one is actually a script, so I changed my bash script git-diff-cmd.sh to the following:
#!/bin/sh
/Applications/Xcode.app/Contents/Developer/usr/bin/opendiff "$2" "$5" -merge "$1" | cat
and git diff can successfully invoke opendiff to do a visual diff.
Can git diff be made to work without needing to install the whole XCode app?
Install the whole BBEdit app instead. It’s small and efficient and does a very nice visual diff.

Copy command issue in Macbook Air

I had faced this issue earlier on the Mac of one of my friends and dismissed it as being something wrong with his Mac, but since I faced it today, it got me a bit worried.
To replicate the issue do the following in a terminal
mkdir -p cp_test/source_folder
echo "This is the file inside" >cp_test/source_folder/trial.txt
echo "This is the file outside" >cp_test/Trial.txt
cd cp_test/
diff Trial.txt source_folder/trial.txt
cp source_folder/trial.txt .
diff Trial.txt source_folder/trial.txt
So basically what happens in my case is that the first time I do a diff, the difference is correctly shown. But the second time there is no difference.
What I gather is that the 'cp' command is copying the file trial.txt to the current directory, and renaming it to Trial.txt (Check the case for the filenames)
I am considering this as a bug, because I don't see this happening on my digital ocean server (Ubuntu 14.04). Not really sure if it is a bug or it is another case of "Apple just does things differently".
This behavior depends on the file system, which may be "case preserving" but "case insensitive" at the same time.

Live reload and asp.net vNext on OSX

How do you get the command "k kestrel" to live-reload (one of the advantage of asp.net vNext) on MacOSX?
Following "k -h", it looks like the command is "k --watch kestrel", however, it do not reload when I make a change into my sample HelloMvc Controller.
At the moment, according to David Fowler, there is a bug in Mono that prohibits detecting file changes. However, a new FileSystemWatcher was supposed to be merged recently so this might work soon!
I have managed to fix this problem by following the suggested solution posted by miguellira on this issue: https://github.com/aspnet/Home/issues/508
I skipped the first the the second steps, I simply changed my ~/.bash_profile by adding the following:
alias dnu="brew switch mono 4.1.0 && dnu"
code () {
brew switch mono 4.0.1
if [[ $# = 0 ]]
then
open -a "Visual Studio Code"
else
[[ $1 = /* ]] && F="$1" || F="$PWD/${1#./}"
open -a "Visual Studio Code" --args "$F"
fi
}
export MONO_MANAGED_WATCHER=enabled
Regarding the bash_profile, if you don't know how to change it (or create it in case you don't have it yet) have a look on this link: https://discussions.apple.com/message/19065947#19065947

command line IntelliJ on Mac OS X

I'm trying to launch IntelliJ on command line in Mac OS X to use it's diff tool. Theoretically idea.sh diff file1 file2 should work. In practice there are some issues with the file which I think I worked around (removing some arguments to readlink etc).
However when it does start, it wants me to enter license information (even though an instance of Intellij is already running and the license is there). Which leads me to believe that there is some sort of separation of command line world vs non-command line world on Mac OS X? IS that true?
Also when I select 30 days eval it proceeds to give me the following exception:
java.lang.IllegalArgumentException: Argument 0 for #NotNull parameter of com/intellij/openapi/fileEditor/impl/FileEditorProviderManagerImpl.getProviders must not be null
at com.intellij.openapi.fileEditor.impl.FileEditorProviderManagerImpl.getProviders(FileEditorProviderManagerImpl.java)
at com.intellij.openapi.diff.impl.highlighting.EditorPlaceHolder.setContent(EditorPlaceHolder.java:73)
at com.intellij.openapi.diff.impl.highlighting.DiffPanelState$1.run(DiffPanelState.java:38)
at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:864)
...
IntelliJ can install a command line launcher for you, adding it to a PATH directory would make it as any other commands on the system. The command is "idea".
Try running /Applications/IntelliJ\ IDEA.app/Contents/MacOS/idea instead. idea.sh is not designed for Mac and will not work without some manual changes.
Another option is to create the command line launcher: Tools | Create Command-line Launcher.
If you are using Toolbox, it provides the way to create the command launcher automatically.
Try:
Tools > Create Commandline Launcher
This will create a command line launcher.
After that you can launch IntelliJ from your desired folder like with a command like this :
idea .
or
idea <path to the folder>
First step, you'll follow and click the menu, Tools > Create Commandline Launcher you'll run this command on what you want open project's directory.
idea .
Idea expects paths to be fully qualified, so I wrote a small helper script. Invoke like:
$ idiff foo.txt bar.txt
The code for idiff:
#!/bin/bash
idea='/Applications/IntelliJ IDEA 10.app/Contents/MacOS/idea'
left=`abspath $1`
right=`abspath $2`
"$idea" diff $left $right
There is probably a real abspath tool somewhere, but I have a simple hand-rolled one:
$ cat `which abspath`
#!/bin/bash
ORIG_DIR=`pwd`
for fn in $* ; do
if [ -e $fn ]; then
d=`dirname $fn`
if [ -z $d ]; then
echo `pwd`/$fn
else
cd $d
echo `pwd`"/"`basename $fn`
fi
else
echo "Don't know how to process $fn" 1>&2
exit 1
fi
cd $ORIG_DIR
done
If you have the toolbox installed, this is now controlled using the Toolbox App Settings.
First enable using the (global) toolbox app settings:
Now, you can enable at the IDE level (here using Intellij):
First you must create the shell scripts to open the IDEs, in the latest version it's done on the Toolbox
Toolbox App > Configuration > Settings > Generate shell script > export to a folder like /User/asilva/IDEs
Then you could call it like ./User/asilva/IDEs/idea or ./User/asilva/IDEs/webstorm
But if you want to call it without the absolute path, the it's needed to add it on the $PATH to be loaded every time the terminal is open:
~/.zshrc
(...)
# idea + webstorm
export PATH="/Users/asilva/IDEs:$PATH"
with this, the webstorm or idea command will be globally available

Resources