This is one of those posts where I risk losing the couple of readers this site has. It’s aimed at true and self-respecting geeks. If scripting, programming and automation are of no interest to you, just keep scrolling, you might find some more palatable posts. But if they are, read on!.
I’ve become dependent of a little server sitting at home. I’m using the term Server very loosely here, as it’s basically an always-on underpowered nettop running Linux. However, it’s all I need for running recurrent tasks (like some of the scripts I have posted here), Plex Media Server and OpenVPN among other things. Although mine is a Linux machine, you can implement this workflow with an always-on Mac or a PC with the appropriate software installed (SSH through CigWin, I think).
Sometimes I need to connect to this server remotely and, although I can do it graphically (e.g. VPN/SSH + VNC), nothing beats the speed and security of doing it through ssh. Prompt for iOS is usually my app of choice for making that connection, but sometimes just running the app to connect to the server and then typing the script name to be run can be tedious and too much work. I wanted a simple, fast and secure way to run a particular script from my iPhone or iPad, without entering a password or switching apps.
There are actually many ways to make a quick and secure connection to a server in order to launch scripts. I think applications such as iSSH allow you to run macros within the app, but I wanted something a little bit more straight forward. My solution involves the following tools:
You can get Pythonista by clicking here from your iOS device. Alternatively, you can click on the banner at the end of this post. Once Pythonista is installed, copy and paste my script (download it here). I put it together based on this excellent post by Stephen Millard. Alternatively, you can install Ole’s script for automatically installing scripts in Pythonista from GitHub and then enter the URL to my script when running it. Ole is the author of awesome Apps like Pythonista and Editorial for iOS.
For the script to work, you must have SSH available at the host computer and you should know its public IP. Additionally, you should have the appropriate ports open in the router/firewall so that you can access that computer from outside. There are tons of posts and tutorials online that explain in detail how to do that. I went through it briefly in a previous post.
The main credentials (Server IP, username and password) are entered in the script header. Please read the comments at the top of the script for more info on these. The script basically performs the following actions:
- Connects to the server.
- Executes the command passed as an argument to the script in Pythonista in the remote server (more info in the following section).
- Once the command is run, it disconnects from the server.
Launch Center Pro
Launch Center Pro is the glue between Pythonista and the scripts in the Server. By using its awesome URL scheme, we can pass the path to the executable script in the server as an argument to the Pythonista script described above, which in turn will run it remotely.
So you just need to create an Action in Launch Center Pro using the following URL as a template:
Just make sure
scriptname.sh can be executed in the remote machine and that you have privileges to run it. That can be achieved by simply typing
chmod +x scriptname.sh in the command line.
Running the script
I’ve created a Group in Launch Center Pro with some of the scripts I run regularly from my iPhone (using Pythonista as an intermediary). So, to run the script, I just need to tap and hold on the group name and then slide the finger on top of the script’s icon I want to run, then release.
After that, Launch Center Pro sprints into action and runs the Pythonista script using the path of the remote script as an argument. Then, a connection to the server is made from Pythonista, the remote script is run, the connection is closed and Boom Shakalaka!, you just ran a remote script by tapping and sliding your finger. If that “done” in the screenshot above does not give you a huge satisfaction, you have ice water in your veins.