Using Apple Shortcuts to Map Network Drives Using Apple & Shell Scripts

Mapping network storage drives is essential for accessing shared files on your network quickly. If you’re using a network storage device with SMB shares, automating the process with AppleScript and Apple Shortcuts can save time. In this guide, we’ll walk you through using AppleScript to map network drives and set up an Apple Shortcut to run the script effortlessly.

We’ll be using the following IP address and share names:

  • IP Address: 192.168.1.100
  • SMB Shares: Podcast, Personal, and Music

Prerequisites

  • A macOS device running macOS Monterey or later (for Apple Shortcuts).
  • Access to the SMB shares on your network storage device (correct credentials and permissions).
  • Basic familiarity with AppleScript and Apple Shortcuts.

Step 1: Write the AppleScript to Mount SMB Drives

AppleScript is a powerful scripting tool built into macOS that allows for automation. Let’s create a script that mounts the Podcast, Personal, and Music SMB shares hosted on the device at 192.168.1.100.

Here’s the AppleScript to mount the shares:

-- Define a handler to connect to SMB shares
on mountSMBShare(shareName)
    try
        set serverAddress to "smb://192.168.1.100/" & shareName
        mount volume serverAddress
    on error errMsg
        display dialog "Failed to mount " & shareName & ": " & errMsg buttons {"OK"} default button "OK"
    end try
end mountSMBShare

-- Mount the Podcast, Personal, and Music shares
mountSMBShare("Podcast")
mountSMBShare("Personal")
mountSMBShare("Music")

How to Use This Script

  1. Open the Script Editor on your Mac (Applications > Utilities > Script Editor).
  2. Paste the AppleScript code above.
  3. Click File > Save, and save the script as MountSMBDrives.scpt. Make sure to select Script as the file format.
  4. Test the script by clicking the Run button inside Script Editor. If successful, the shares will appear in Finder under “Network.”

Step 2: Set Up the Script in Apple Shortcuts

Apple Shortcuts allows you to trigger actions with a single click. Let’s integrate our AppleScript into a Shortcut for easy access.

How to Create the Shortcut

  1. Open the Shortcuts app on your Mac.
  2. Click the + button to create a new shortcut.
  3. Click Add Action and search for Run AppleScript.
  4. Paste the AppleScript from Step 1 into the action.
  5. Test the shortcut by clicking Run in the Shortcuts app. If everything is configured correctly, the SMB shares should be mounted.
  6. Save the shortcut with a name like Mount SMB Drives.

Step 3: Add the Shortcut to the Menu Bar or Desktop

To make the shortcut even more accessible, you can add it to the menu bar or create a desktop shortcut.

To Add to the Menu Bar

  1. Open the Shortcuts app.
  2. Click the three dots on the Mount SMB Drives shortcut.
  3. Toggle Pin in Menu Bar.

To Add to the Desktop

  1. In the Shortcuts app, right-click the Mount SMB Drives shortcut.
  2. Click Create Alias and drag the alias to your desktop.

Step 4: (Optional) Automate the Shortcut on Login

You can configure the shortcut to run every time your Mac logs in, ensuring your SMB shares are always mounted.

  1. Open System Settings > Users & Groups.
  2. Select your user account and click Login Items.
  3. Click the + button and select your shortcut alias from the desktop.

Conclusion

Using AppleScript with Apple Shortcuts is a powerful way to map SMB network drives quickly. This setup allows you to avoid manually connecting to the drives every time you boot your Mac or need access to shared storage. With just one click, or even automated at login, you’ll have instant access to your Podcast, Personal, and Music shares.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.