Creating a Shortcut for iOS: Using Swift on a Raspberry Pi with OpenJelly

Learn how to create an iOS or macOS Shortcut using Jelly Lang and the OpenJelly compiler on a Raspberry Pi or other Linux machine. Step-by-step guide included.

Creating a Shortcut for iOS: Using Swift on a Raspberry Pi with OpenJelly

The Raspberry Pi, a credit-card-sized computer, exemplifies the spirit of openness and accessibility in technology. It's a testament to how powerful and versatile tiny, affordable devices can be, rivaling even mobile phones in compute power. Moreover, for many developers, the physical keyboard is an essential tool, enabling creativity and productivity. If you can build on a Raspberry Pi, you can certainly build on macOS.

In this first article of our two-part series, we'll guide you through the steps of installing Swift on a Raspberry Pi. With Swift set up, you'll be ready to install OpenJelly in our next article.

Why Choose Raspberry Pi?

  1. Embracing Openness and Accessibility: The Raspberry Pi epitomizes the ethos of open-source hardware, democratizing technology for all.

  2. Harnessing Robust Computing Power: Despite its diminutive stature, the Raspberry Pi packs a punch, rivaling the computational capabilities of many smartphones.

  3. Empowering Developers: With its physical keyboard and comprehensive development environment, the Raspberry Pi emerges as an idyllic platform for coding endeavors.

Roadmap

  1. Deploy Docker via apt

  2. Swift Installation via docker

  3. Cloning Open-Jellycore for Compiler for Shortcut Creation

  4. Compilation of jelly Tool for Shortcut Generation

  5. Crafting a "HelloWorld.shortcut"

Getting Started

Prerequisites

• A Raspberry Pi 5 (or 4) with Raspbian OS installed.
• Stable internet connectivity.
• A keyboard and monitor tethered to your Raspberry Pi.

Step 0: Update and Upgrade Your System

First, ensure your system is up-to-date by running the following commands in the terminal:

sudo apt update
sudo apt upgrade -y

Step 1. Install Docker

We will be installing Swift via Docker. Therefore, the first step is to install Docker.

a. Run the following command to uninstall all conflicting packages.

for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done

b. Set up Docker's apt repository

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

c. Install Docker packages

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

d. Verify things work

sudo docker run hello-world

If You See this Prompt, You're Good

Step 2. Install more Dependencies

Swift requires several dependencies to be installed. Execute the following commands to install them.

# Summon clang, the Swift compiler:
sudo apt-get install clang libicu-dev

# Call forth libcurl, facilitating URL data transfer:
sudo apt-get install libcurl4-openssl-dev

# Enlist libbsd, providing BSD system functions:
sudo apt-get install libbsd-dev

These dependencies furnish the requisite tools and libraries for Swift's seamless operation on your Raspberry Pi.

Step 3. Install Swift via Docker

a. Pull the Swift Docker image from Docker Hub.

sudo docker pull swift

b. Create a container using the tag latest and attach it to the container.

sudo docker run --privileged --interactive --tty --name swift-latest swift:latest /bin/bash

c. Start container swift-latest

sudo docker start swift-latest

d. Attached to swift-latest container

sudo docker attach swift-latest

Step 4. Download OpenJelly-Jellycore

Just to recap, we now have Swift installed on our computer via Docker. The next step is for us is to download Open-Jellycore from Github. Next bridge those files on our hard driver to our Docker container.

You can download the Git repo anywhere on your desktop. In the spirit of macOS, I will create a ~/Developer folder and build from there.

mkdir ~/Developer/ && cd ~/Developer
git clone https://github.com/OpenJelly/Open-Jellycore.git

Change directory into the downloaded folder.

cd ~/Developer/Open-Jellycore

Step 5. Build jelly

To create Shortcuts using Jelly Language, we need to build the jelly executable. We will accomplish that using Swift. To get started, we first need to connect Swift --which is inside a Docker container-- with our Open-Jellycore directory.

a. Check which docker images are currently running

sudo docker ps

b. Check which docker images are available

sudo docker images

docker_ps.png

c. Run the docker image that contains Swift

Looking at my images from the previous command, one REPOSITORY says "swift". This is the container I want to launch.

sudo docker run -it <either_swift_or_image_id> /bin/bash

Take Notice that if Run is Successful, you are now as Root

d. Once the container is loaded, find the Swift path

which swift

docker-load-swift-which-path.png

In our example, docker does provide environmental variables.

env | grep SWIFT

env_grep_swift.png

Step 6. Setting Up Docker Volumes

To map a directory from your host system (in this case, your Raspberry Pi) to a location within the Docker container, you can use Docker volumes or bind mounts. This allows you to access files and directories on your host system from within the container.

We are going to use Docker Volumes and map /usr/bin/swift directory in the container to ~/Developer/Open-Jellycore on your Raspberry Pi.

This command will start a new Docker container based on the Swift image, mount the ~/Developer/Open-Jellycore directory on your Raspberry Pi to the /mnt/swift directory inside the container, and then provide you with an interactive shell (/bin/bash) inside the container.

sudo docker run -it -v ~/Developer/Open-Jellycore/:/mnt/swift swift /bin/bash

Within the Docker container:

cd /mnt/swift/resources
./build.sh

Step 7. Moving jelly Executable

Within the Docker container, copy jelly to /usr/local/bin.

cp /mnt/swift/.build/jelly /usr/bin/

Make the jelly executable.

chmod +x /usr/bin/jelly

Verify jelly is installed.

which jelly

Step 8. Create a Shortcut

Change directory back to the shared folder.

cd /mnt/swift/resources
jelly Hello.jelly --export --out ./helloworld.shortcut

helloworld.shortcut.png


FAQs

Why create Shortcuts on a Raspeberry Pi? Aren't Shortcuts for iOS only?

While Shortcuts are used on iOS and macOS devices, there are many developers who prefer to create on -NIX machines. This article focuses on providing options to developers and celebrate the importance of OpenJelly by giving a head nod to the OG OS. .

Why did this article decide to use Docker for Swift?

This article opted for Docker to install Swift due to its streamlined deployment process, ensuring consistent behavior across systems, simplifying setup, and enhancing portability. Docker's containerization technology isolates Swift and its dependencies, minimizing conflicts and promoting reproducibility, making it an ideal choice for accessible and hassle-free Swift installation on Raspberry Pi.

I can't install this on my iOS device. How can I sign my Shortcut?

To sign your shortcut, you'll require access to a signing server, typically provided by subscribing to JellyCuts.com. Becoming a paying subscriber grants you access to HubSign, enabling you to sign your shortcut securely and ensure its authenticity.

Subscribe Today

How can I create a Shortcut using just my iOS device?

Download Jellycuts for iOS and create shortcuts from your iPhone or iPad.


Troubleshooting

If you would prefer not to use sudo, you can modify your permissions by adding docker to your groups.

sudo usermod -aG docker <NAME OF YOUR USER>

Next, you will need to log-out of your computer then log back in.

Run this command one more time and if you see docker, you are good.

groups

Resources