cover image
< Home
IoT

Remote Editing Raspberry Pi Files from Mac with Visual Studio Code

When programming applications that run embedded on a Raspberry Pi, it is often convenient to work on a more powerful machine. In this article, I want to show how to edit remotely from a Mac programming code that runs directly on the Raspberry Pi. As a comfortable IDE I use Visual Studio Code.

Sharing Folder on Raspberry Pi

Since I want to access files from my Mac, I can use a tool called netatalk. Netatalk is a free and open source implementation of Apple's Apple Filing Protocol (AFP). AFP is now deprecated, but it still works on Macs with macOS Monterey.

In order to install netatalk you need to enter the following in your Raspberry Pi shell:

sudo apt update
sudo apt install netatalk

You need to configure the folders you want to share with your Mac in a file called /etc/netatalk/afp.conf.

This is the minimal configuration you need to add:

[Homes]
basedir regex = Full path to your base directory of the user you want to share folders in

[Name of your share]
path = Full path of your folder you want to share

Adapt the path values to your folder and specify the name of the share in the afp.conf file.

After you have finished editing, restart netatalk with:

sudo systemctl restart netatalk

In order to start netatalk automatically on every boot, run this command:

sudo systemctl enable netatalk

Adding Folder to Mac

In your Mac you can now open the Finder application and search in your network for the Rasperry Pi labeled with the share name you specified in the afp.conf.

Double click to connect and enter the credentials of your Raspberry Pi user. You should now see the files of you shared Raspberry Pi folder in your Finder.

Adding Folder to Visual Studio Code

In Visual Studio Code, you can now go to the Explorer view and select in the File menu the menu item "Add Folder to Workspace". You can now select your shared folder and add it to your projects workspace.

Finally, you can edit files directly in Visual Studio Code on your Mac. On save, they are transferred to the Raspberry Pi and stored there.

Conclusion

Embedded programming on a Raspberry Pi can often feel slow with modern IDEs. But I hope I could show that it is not that difficult to set up a file share for comfortable remote editing with Visual Studio Code on your Mac.

References

  • Raspberry Pi: https://www.raspberrypi.com/

  • Netatalk: https://github.com/Netatalk/Netatalk

  • Apple Filing Protocol: https://developer.apple.com/library/archive/documentation/Networking/Conceptual/AFP/Introduction/Introduction.html

  • Visual Studio Code: https://code.visualstudio.com/

  • Cover image: https://pixabay.com/photos/iceland-sky-clouds-beautiful-1995039

Published

23 Aug 2022

Thomas Derflinger

Written by Thomas Derflinger

I am a visionary entrepreneur and software developer. In this blog I mainly write about web programming and related topics like IoT.