Raname Folder

lpadmin
Contributor

Hello I am looking to rename a folder via a script. I am trying to use

mv ~/Google Drive ~/OldGoogleDrive

This worked on my computer, but when I tried it on another it gave me the following error.

Executing Policy Rename Google Drive Folder
Running script Rename Google Drive Folder...
Script exit code: 1
Script result: mv: rename /var/root/Google Drive to /var/root/OldGoogleDrive: No such file or directory<br/>
Error running script: return code was 1.

For some reason on this computer it is looking for the folder in the var/root location, even though on my computer it did not look there. Any help is greatly appreciated.

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

~ doesn't work in scripts run from Jamf Pro, because that typically evaluates to /var/root/ just as the error message indicated. The ~ is used as a placeholder for, "path to the home folder of whoever is running the script". When you run the script it correctly looks in your home folder, but when Jamf Pro runs it, it goes to the root account, since that's who's actually running the script.

Anyway, use a variable placeholder for the logged in user, if there is one.

#!/bin/sh

loggedInUser=$(stat -f%Su /dev/console)

mv /Users/$loggedInUser/Google Drive /Users/$loggedInUser/OldGoogleDrive

View solution in original post

2 REPLIES 2

lpadmin
Contributor

Here is the file path of the folder I am renaming.
/Users/davidharborth/Google Drive

mm2270
Legendary Contributor III

~ doesn't work in scripts run from Jamf Pro, because that typically evaluates to /var/root/ just as the error message indicated. The ~ is used as a placeholder for, "path to the home folder of whoever is running the script". When you run the script it correctly looks in your home folder, but when Jamf Pro runs it, it goes to the root account, since that's who's actually running the script.

Anyway, use a variable placeholder for the logged in user, if there is one.

#!/bin/sh

loggedInUser=$(stat -f%Su /dev/console)

mv /Users/$loggedInUser/Google Drive /Users/$loggedInUser/OldGoogleDrive