I've written and AppleScript App that runs a "mount -t smbfs " command to mount a Windows Shared drive that our Staff use.
The App has been used successfully for a number of months until today. If a user has an # symbol in their password the application fails. The path is rejected.
Here's the script:
-- Teaching Drive Access
--Get The Shortname and PC Password of current user
--set PCusername to (short user name of (system info))
set PCusername to "benstaff"
--set PCPassword to text returned of (display dialog "What's your PC Password?" default answer "" with title "T Drive" with icon stop with hidden answer)
--Create Sharepoint on Desktop
set FolderTarget to (path to desktop folder as text) & "DoNotUseTeachingDrive"
try
FolderTarget as alias
on error
do shell script "mkdir /Users/" & PCusername & "/Desktop/DoNotUseTeachingDrive/"
end try
set mountcommand to "mount -t smbfs "
set mountuser to "//" & PCusername & ":" & PCPassword
set mountuser to "//" & PCusername & ":" & PCPassword
set mountvolume to "#ncs-srv-fs3.ncs.local/Teaching"
set machomepath to "/Users/" & PCusername & "/Desktop/DoNotUseTeachingDrive/"
set mountwindowshome to mountcommand & mountuser & mountvolume & " " & machomepath as string
do shell script mountwindowshome
The full output of the mountwindowshome is:
mount -t smbfs //mystaff:PE91XA!!##ncs-srv-fs3.ncs.local/Teaching /Users/mystaff/Desktop/DoNotUseTeachingDrive/
If I run the command in the Terminal without the password I am asked for a password and the share is mounted correctly.
Any help/pointers would be gratefully received.
According to this site, you have to use url escaping on special characters. For the # character that would be %40, which would turn the mount line into this:
mount -t smbfs //mystaff:PE91XA!!%40#ncs-srv-fs3.ncs.local/Teaching /Users/mystaff/Desktop/DoNotUseTeachingDrive/
Related
I am attempting to create a script that will grab the serial number of the Mac and set it to the HostName, LocalHostName, & ComputerName with out it prompting for administrator credentials. So far this is what I have and trying to work through it.
How do I put the credentials in the script to where it pulls the info without prompting?
set sys to do shell script "/usr/sbin/system_profiler SPHardwareDataType " without altering line endings
set StringVariable1 to "Serial"
set Serial_Number to do shell script "/usr/sbin/system_profiler SPHardwareDataType | awk '/Serial/ { print $NF }' "
do shell script "scutil --set HostName " & Serial_Number with administrator privileges
do shell script "scutil --set LocalHostName " & Serial_Number with administrator privileges
do shell script "scutil --set ComputerName " & Serial_Number with administrator privileges
display dialog "The Mac has been renamed to " & Serial_Number
I am not sure how to place the Unix commands in a VBScript file.
I am trying to write a code in VBScript where we can copy our files from our Windows folder to Unix directory.
Here writing files in the our Unix directory requires username and password.
I explored and found that we can use SCP command this way to copy files:
scp d:/folders/hello.txt /abc_st/batchrepo/inbox
# I am still exploring for copying files from Unix to Windows
And for Username/Password, I found that we can use sshpass command like below before scp command:
sshpass -p "your password"
# I still have to explore on this as I cant see the place for username.
Could someone please suggest how can I place these commands in a VBScript file.
I'll be placing this VBScript into an HTML file.
Thanks.
VBScript doesn't support SSH by itself, so you need some kind of scp utility for copying files from a Windows host to a Unix host, for instance pscp.exe from the PuTTY suite, or the ssh package in Cygwin.
Assuming you're using pscp.exe you can run the client by shelling out like this:
Set sh = CreateObject("WScript.Shell")
sh.Run "C:\path\to\pscp.exe -pw PASS D:\folders\hello.txt unixhost:/abc_st/batchrepo/inbox", 0, True
Make sure to quote paths if they contain spaces:
Function qq(str) : qq = Chr(34) & str & Chr(34) : End Function
Set sh = CreateObject("WScript.Shell")
sh.Run qq("C:\path\to\pscp.exe") & " -pw PASS " & qq("D:\folders\hello.txt") _
& " unixhost:/abc_st/batchrepo/inbox", 0, True
I am running a script in AppleScript in which I use tell application "Terminal" to do a specific script that needs sudo privileges in Terminal. When prompted, the user running the script must enter the sudo password in Terminal to allow the script to bind the laptop to active directory.
What command can I use to get the script to stop running if the sudo password entered in Terminal is incorrect? Right now if the user enters the password incorrectly, the script will keep running the rest of the commands except it ultimately fails in the end because it is unable to bind to AD without the credentials to do so.
May I ask why you're running this code specifically in the Terminal.app? When using a do shell script you can run the do shell script with administrator privileges (equivalent to sudo) and without using Terminal.app.
do shell script "disconfigad -f -a " & computerName & " -domain .local -u " & user_name & "-p" & user_password & " -ou 'CN=Computers,DC=,DC=local'" user name "<administrator>" password "<password>" with administrator privilege
I have a script written that duplicates most of the home folders (excluding library) to a shared server just for back-up purposes. But i'm confused on how to mount the drive via AppleScript since the shared server folder is on the domain but not actually local. All computers I've tested the script on are connected to the domain directly and not through VPN.
I've tried prompting the user for username and password and then setting them as variables so that I could use them when mounting the drive. But it doesn't work as of this moment. I've tried doing the following.
"smb://domain;" & user_name & "#serverpath/" & user_name &
"smb://domain;" & user_name &":"&user_pass& "#serverpath/" & user_name &
I've also tried leaving the domain out of it, which didn't help either. Still getting an error
Finder got an error: AppleEvent handler failed.
This Applescript works for me:
set usr to "FSB" & "\\" & "u012875902"
set pw to "oblongata"
mount volume "smb://10.111.123.122/servoy" as user name usr with password pw
We are trying to install an app thru Applescript using terminal commands as mentioned below. Firstly it will mount the dmg file and then install the app to App folder.
While installing app to App folder its asking for password, how to handle this password using Applescript??
hdiutil mount /Users/rajasekaranr/Downloads/install_flash_player_osx.dmg"
sudo cp -R "/Volumes/Flash Player 2/Install Adobe Flash Player.app" /Applications
Error while executing the above commands using apple script
error "sudo: no tty present and no askpass program specified" number 1
Try:
property usr : "username"
property pswd : "password"
set fromPath to quoted form of "/Volumes/Flash Player 2/Install Adobe Flash Player.app"
set toPath to quoted form of "/Applications"
do shell script "cp -R " & fromPath & space & toPath user name usr password pswd with administrator privileges