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
, andMusic
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
- Open the Script Editor on your Mac (
Applications
>Utilities
>Script Editor
). - Paste the AppleScript code above.
- Click File > Save, and save the script as
MountSMBDrives.scpt
. Make sure to selectScript
as the file format. - 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
- Open the Shortcuts app on your Mac.
- Click the + button to create a new shortcut.
- Click Add Action and search for Run AppleScript.
- Paste the AppleScript from Step 1 into the action.
- Test the shortcut by clicking Run in the Shortcuts app. If everything is configured correctly, the SMB shares should be mounted.
- 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
- Open the Shortcuts app.
- Click the three dots on the
Mount SMB Drives
shortcut. - Toggle Pin in Menu Bar.
To Add to the Desktop
- In the Shortcuts app, right-click the
Mount SMB Drives
shortcut. - 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.
- Open System Settings > Users & Groups.
- Select your user account and click Login Items.
- 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.