How can I find the device uuid's of all connected devices through a command line script? - iphone

I am running automated tests on iOS devices. I want to not have to always have all devices connected. So I want to find all device id's and then only start the process of building, deploying, and running tests if that device is connected.
So my question is, how can I find the device uuid's of all connected devices through a shell script?
Thanks!

Edit:
instruments command is now deprecated, you should run instead
xcrun xctrace list devices
Previous answer:
If you have Xcode installed, you can use Instruments to get all known devices also. With
instruments -s devices

The answer from #KKendall set me on the right path. Here's a version with a single sed expression:
system_profiler SPUSBDataType | sed -n -E -e '/(iPhone|iPad)/,/Serial/s/ *Serial Number: *(.+)/\1/p'

install ideviceinstaller on Mac OS X via brew command:
brew install ideviceinstaller
then idevice_id -l will work from terminal

I found a similar question about using multiple devices here is my form of the answer that helped me:
#!/bin/sh
i=0
for line in $(system_profiler SPUSBDataType | sed -n -e '/iPad/,/Serial/p' -e '/iPhone/,/Serial/p' | grep "Serial Number:" | awk -F ": " '{print $2}'); do
UDID=${line}
echo $UDID
udid_array[i]=${line}
i=$(($i+1))
done
cnt=${#udid_array[#]}
for ((i=0;i<cnt;i++)); do
echo ${udid_array[i]}
done

Also ios-deploy can be used:
ios-deploy -c | grep -oE 'Found ([0-9A-Za-z\-]+)' | sed 's/Found //g'

If you have XCode go to Window > Devices & Simulators. On that page, any connected device will display along with other IDs and stats on your device. This will also connect to devices over WIFI.

Related

Not getting the package and current focus information when using dumpsys adb shell command

Not getting the package and current focus information when using: 1|m21:/ $ dumpsys window windows | grep -E 'mCurrentFocus', no information is getting displayed.
Those who are going through same issue can try following command:
--> adb shell "dumpsys window windows | grep -E 'mTopActivityComponent'"
It is working and giving the details of the information needed

Raspberry Pi / Octopi USB Camera Setup: What does this mean and how do I use it?

I'm very new to Raspberry Pi, and have no prior notable experience with Linux so this is all new to me...
Octoprint is a 3D printer spooler that you can run on your raspberry pi. One of the features on Octoprint is the ability to setup a USB camera to view either still images or a stream of your print.
I am using the Octopi prepackaged Octoprint image.
Octoprint's github contains the following info referring to my USB camera. But I have no idea how to implement this.
Hama PC-Webcam "AC-150" on Raspberry Pi
./mjpg_streamer -o output_http.so -w ./www -i input_uvc.so -y -r 640x480 -f 10
https://github.com/foosel/OctoPrint/wiki/Webcams-known-to-work
I'm guessing this is an easy command that I enter via console, but I've winged few commands with no luck. Can someone shed some light on how I use this? Like I said I'm an absolute beginner with the pi...
Any help is greatly appreciated!
Try this:
camera_usb_options="-r VGA -f 10 -y"
sudo service octoprint stop
fuser /dev/video0
/dev/video0: **1871m**
$ ps axl | grep **1871** *Change this number by yours*
$ kill -9 **1871**
./mjpg_streamer -i "input_uvc.so $camera_usb_options" -o "output_http.so -w ./www"
sudo service octoprint start

How to send data to command line after calling .sh file?

I want to install Anaconda through EasyBuild. EasyBuild is a software to manage software installation on clusters. Anaconda can be installed with sh Anaconda.sh.
However, after running I have to accept the License agreement and give the installation location on the command line by entering <Enter>, yes <Enter>, path/where/to/install/ <Enter>.
Because this has to be installed automatically I want to do the accepting of terms and giving the install location in one line. I tried to do it like this:
sh Anaconda.sh < <(echo) >/dev/null < <(echo yes) >/dev/null \
< <(echo /apps/software/Anaconda/1.8.0-Linux-x86_64/) > test.txt
From the test.txt I can read that the first echo works as <Enter>, but I can't figure out how to accept the License agreement, as it sees it now as not sending yes:
Do you approve the license terms? [yes|no]
[no] >>> The license agreement wasn't approved, aborting installation.
How can I send the yes correctly to the script input?
Edit: Sorry, I missed the part about having to enter more then one thing. You can take a look at writing expect scripts. thegeekstuff.com/2010/10/expect-examples. You may need to install it however.
You could try piping with the following command: yes yes | sh Anaconda.sh. Read the man pages for more information man yes.
Expect is a great way to go and probably the most error proof way. If you know all the questions I think you could do this by just writing a file with the answers in the correct order, one per line and piping it in.
That install script is huge so as long as you can verify you know all the questions you could give this a try.
In my simple tests it works.
I have a test script that looks like this:
#!/bin/sh
echo -n "Do you accept "
read ANS
echo $ANS
echo -n "Install path: "
read ANS
echo $ANS
and an answers file that looks like this:
Y
/usr
Running it like so works... perhaps it will work for your monster install file as well.
cat answers | ./test.sh
Do you accept Y
Install path: /usr
If that doesn't work then the script is likely flushing and you will have to use expect or pexpect.
Good luck!
Actually, I downloaded and looked at the anaconda install script. Looks like it takes command line arguments.
/bin/bash Anaconda-2.2.0-Linux-x86_64.sh -h
usage: Anaconda-2.2.0-Linux-x86_64.sh [options]
Installs Anaconda 2.2.0
-b run install in batch mode (without manual intervention),
it is expected the license terms are agreed upon
-f no error if install prefix already exists
-h print this help message and exit
-p PREFIX install prefix, defaults to /home/cody.stevens/anaconda
Use the -b and -p options...
so use it like so:
/bin/bash Anaconda-2.2.0-Linux-x86_64.sh -b -p /usr
Also of note.. that script explicitly says not to run with '.' or 'sh' but 'bash' so they must have some dependency on a feature of bash.
--
Cody

Capture/Record Audio Input in RaspberryPi

I bought a USB Audio Controller for RaspberryPi, in order to capture Audio input. I already done below steps on Rasbian but still unsure about Audio Capturing.
Can you please guide me on how do I get it?
Type the following commands to install the Audio device
pi#raspberrypi ~ $ sudo apt-get install alsa-utils
Detection Successfully by
pi#raspberrypi ~ $ lsusb
pi#raspberrypi ~ $ amixer
pi#raspberrypi ~ $ alsamixer
Also configure USB Audio device to make it default
/etc/modprobe.d/alsa-base.conf
by adding pound/hash symbol with
options snd-usb-audio index=2
#options snd-usb-audio index=2
simply write this command of Command Terminal, in order to record Audio
arecord -f cd -D plughw:0 -d 10 a.wav
Let me know if you get further any issue in recording sound

Can the UI Automation instrument be run from the command line?

Is there a way to open the UIAutomation instrument through the terminal?
Will it be possible to write an AppleScript to open Apple's UIAutomation tool and load the application to be tested?
Can you please tell me is there any way through scripting or through the command line we can open UIAutomation and select the app to be tested, as well as select the test script?
instruments -t /Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/\
PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate \
<full_path_to_application> -e UIASCRIPT <path_to_script.js> \
-e UIARESULTSPATH <output_results_path>
for xcode >= 4.5
instruments -t
/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/\
AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate \
<full_path_to_application> -e UIASCRIPT <path_to_script.js> \
-e UIARESULTSPATH <output_results_path>
for xcode >= 6.1
instruments -w <device ID> -t \
/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/\
AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate \
<full_path_to_application> -e UIASCRIPT <path_to_script.js> \
-e UIARESULTSPATH <output_results_path>
There a few important things to note though:
the -w parameter is not required unless you want to run the scripts on your device. If you want to run your scripts on the simulator, simply omit this parameter from the command.
full_path_to_application is the path to your .app file that is created by your simulator. For me, the path was
/Users/fwasim/Library/Application Support/iPhone Simulator/5.0/Applications/AA6BA2E1-D505-4864-BECC-29ADEE28194D/name_of_application.app
this path might be different for anyone else depending on what iOS version are you running on your simulator. Also remember to put this path in double quotation marks.
The path_to_script.js should be the FULL PATH to where your automation script written in javascript is saved. Also remember to put this path in double quotation marks.
Lastly output results path is the path where you want to save the output results. Also remember to put this path in double quotation marks.
These were the points I had been missing on and thus was getting some of the errors mentioned above.
Starting UIAutomation via command line
You can do it now, starting with XCode 4.2 for iOS5 beta 4
From command line, you can run instruments pointing to the automation template and specify as environment variables the test script you want to execute and destination path for results:
instruments -w -t /Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate -e UIASCRIPT
Above is from this source url:
http://dev-ios.blogspot.com/2011/07/starting-uiautomation-via-command-line.html
See some more details on command line from Apple at:
http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/instruments.1.html
Plus post from Stacktrace user on command line run with iphone iOS UIAutomation
Can Instruments be used using the command line?
Hope this helps- have a good day :)
Updated and tested for Xcode 6.0.1:
instruments -w 'iPhone 5s' \
-t '/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate' \
'/Users/sohail/Library/Developer/CoreSimulator/Devices/7232A640-A9D2-4626-A2AD-37AFFF706718/data/Containers/Bundle/Application/E71B915E-051D-4BEF-9083-34416D02EC91/RoadRunnerRadar.app' \
-e UIASCRIPT '/Users/sohail/Developer/clients/acme/roadrunnerradar/ACMERoadRunnerRadarAutomationTests/TestRunner.js' \
-e UIARESULTSPATH '/Users/sohail/Developer/clients/acme/roadrunnerradar/ACMERoadRunnerRadarAutomationTests/TestResults/'
Inspired by others who wrote command-line wrappers that haven't been updated in a while, and thus didn't work (and seemed difficult to make sense of as I was tempted to resurrect them), I wrote a bash shell script that I believe will be more transparent, lighter and thus, easier to maintain.
You can find the project on github and a companion blog post.
Instead of the long instruments command, I wrote a wrapper that is easier to use: https://github.com/enriquez/uiauto
To use it, you just have to do the following:
Build your project in Xcode for the simulator (device support coming soon).
cd to where your project's .xcodeproj or .xcworkspace is located.
Run uiauto exec path/to/your/script.js.
With every new version of Xcode the template path seems to be changed. One of the best ways find out the path of the template is instruments -s command which would list out all the available templates.
I also very intrested in this topic. What I actually found is this reference which shows that there is way to launch instruments from terminal with predefined template, location where results should be stored, and target device on which it should run, and other parameters. You can also just type in terminal instruments to get parameters list.
I was unsuccessful with running UI Automation on iPhone this way. I haven't try simulator or mac app since I am mostly interested in device. I posted a question here on SO but from the lack of any response I think that not many people are using instruments this way.
But there is hope to get it running, as there is this short thread on apple developer forum (you need to log in) that suggest that it can be done. I will be trying that later, if I will succeed I will post solution here. If you will manage to make it running pleas post your way here, as I (and probably others) will be interested.
there's a tool for record/replay UI events with shell environment, and could writting script with ruby.
interactive iPhone application development
http://github.com/wookay/libcat
Type this command in terminal instruments -s, you get template path after type:
instruments -t <template path> <Application file path> -e UIASCRIPT <script.js> UIARESULTPATH <result_path>
The right way to do it on a iOS simulator is as follows:
instruments -w 'iPhone 5s (9.1)' \
-t '/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate' \
'justTheNameOfYourAppDontAddExtension' \
-e UIASCRIPT '/Users/barry/Dropbox/Public/login.js' \
-e UIARESULTSPATH '/Users/barry/Dropbox/Public/