Showing posts with label osx. Show all posts
Showing posts with label osx. Show all posts

Thursday, 28 July 2016

Automator (OSX): 2 handy ideas


Automator is a tool shipped with OSX: it allows user to create simple applications that automates manual task. You can find some guide on how to use it, like this one.
Even if it is possible to record and save actions mad on the computer, I recommend to create the script manually.

In the last year I used this application for 2 scenarios.

Automatic launch applications for a Demo

When you create a demo for a presentation, it is important to be prepared and make no error: time is very important!
In november I did a speech with a final "demo".
The demo used a series of applications launched from the terminal:


The explanation of the above workflow:
  • opens a terminal
  • executes a command on the terminal (using keystrokes)
  • opens a new tab thanks to keypress [command + t]
  • executes another command
  • opens a third tab
  • keystrokes another command
  • opens the last tab, change the directory, launch a node script

Automatic Screenshots

Recently I subscribed an e-learning service with slides, available only online.
I wanted to have the same slides offline.
Thanks to automator it was possible to:
  • record the action to: select a window(the browser) and click on it. A click move the slide to the next one.
  • use screencapture to save in a predefined directory a screenshot of the entire screen. (using a bash command to build a unique filename each time).
  • repeat the step a variable number of times.
The script follows:



Thursday, 19 July 2012

Make Osx talks with a Bluetooth GPS

This GPS:
Everything started one week ago when I had a new project in mind.
In this project (I will talk about it in a future post) I have to make my android phone talk with my macbook through bluetooth.
What I need to do:

- expose an RfComm Service on Android device
- search the device from the mac (inquiry)
- establish a connection between the phone and my mac through bluetooth
- pass data between phone and mac

Use a gps bluetooth is enough for a simulation of these operations.


The problems
Documentation.
Yes, this is the first problem.
The second one is .. I've never developed something for OsX but I have did something with IOS (it helps).
Since the arrive of Bluetooth 4.0 LE, Apple make some changes to the bluetooth library.
For what I've seen from the Apple documentation, they did a lot of improvements to make the new library easy to use.
Only new apple product support BT4.0LE... if you have to talk with previous BT device.. you need to use old library.
My Mac and my btgps are old.. so no BT4.
I didn't find any documentation on how to use the old library.. so you have to surf the web searching for the answers.
 

The code
The code is here(the important stuff, you need to customize it) is on gist.github.com and this is how it works:
  • after application is started it search bt devices and get the names of all the visible bluetooth device (this is called inquiry). In this step I search for the BT Device with the name "HBTGPS" and I save the reference locally. 
  • the second step is searching for the available services on the device.  (it is called SDP: service discovery protocol). Every Bluetooth device can have one ore more services to expose.
  • the third step is: check if RfComm service is present on the device and get the channel on which RfComm is available. A service is bound to a channel.
  • Last step, with the channel and the reference of the bluetooth device I can open the connection and start getting data from the device. Here there are some protocol methoeds call after every change.
This is the output of the program:
2012-07-19 01:19:05.427 FMOSXAPP[406:903] ok, go on
2012-07-19 01:19:05.452 FMOSXAPP[406:903] Let's start inquiry devices around me
2012-07-19 01:19:05.621 FMOSXAPP[406:903] found this device 00-0a-1a-17-88-d6
2012-07-19 01:19:18.335 FMOSXAPP[406:903] updating names for: 1
2012-07-19 01:19:18.435 FMOSXAPP[406:903] That's my boy! HBTGPS
2012-07-19 01:19:18.437 FMOSXAPP[406:903] I gottcha!
2012-07-19 01:19:18.443 FMOSXAPP[406:903] Service: SPP slave
2012-07-19 01:19:18.444 FMOSXAPP[406:903] ChannelID FOUND 1 1
2012-07-19 01:19:18.444 FMOSXAPP[406:903] Found rfcomm channel on device.. 1
2012-07-19 01:19:20.332 FMOSXAPP[406:903] channel complete
2012-07-19 01:19:20.469 FMOSXAPP[406:903] received: ,000,*71
$GPGSV,2,2,08,04,00,000,,04,00,000,,31,00,000,,07,00,000,*71
$GPRMC,000027.0,V,1438.70599,N,01215.00413,E,,,010100,,,N*70
$GPGGA,000038.0,4128.70599,N,01215.00423,E,0,00,,-00027,M,,,,*1F
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,2,1,01,09,00,000,,25,00,000,,08,00,000,,27,00,000,*71
$GPGSV,2,2,03,06,00,000,,03,
2012-07-19 01:19:20.476



(I've changed a little bit the data from the gps.. just for privacy :P)