Hey Jonas,
You’re right—using a Bash script for this is a cleaner approach, especially when deploying via Jamf. Below is a Bash script that replicates your AppleScript functionality. It dynamically retrieves the currently logged-in user and mounts the SMB share accordingly:
#!/bin/bash
# Get the currently logged-in user
currentUser=$(stat -f%Su /dev/console)
# Define the SMB share path
serverAddress="our_server_address"
sharePath="smb://$serverAddress/homes/$currentUser"
# Check if the share is already mounted
if mount | grep "$sharePath" > /dev/null; then
echo "Share already mounted."
exit 0
fi
# Create mount point if it doesn't exist
mountPoint="/Volumes/$currentUser"
if [ ! -d "$mountPoint" ]; then
mkdir -p "$mountPoint"
fi
# Mount the SMB share
osascript -e "try" -e "mount volume \\"$sharePath\\"" -e "end try"
# Verify if the mount was successful
if mount | grep "$serverAddress"; then
echo "Successfully mounted $sharePath"
else
echo "Failed to mount $sharePath"
exit 1
fi
Explanation:
- •Retrieves the currently logged-in user with stat -f%Su /dev/console
- •Constructs the SMB path dynamically
- •Checks if the share is already mounted before proceeding
- •Creates a mount point if it doesn’t exist
- •Uses osascript to mount the volume via Finder, avoiding password prompts when possible
- •Verifies if the mount was successful
This should work seamlessly in Jamf deployments. Let me know if you need any tweaks!