Applescript Error - applescript

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

Related

Which user is AppleScript using when executing scripts

• Here is the script to be executed via AppleScript:
bash-3.2$ cd /Users/jack/Desktop/
bash-3.2$ ls -l | grep static
-rwxrwxrwx 1 jack admin 65 5 May 08:10 static-routes.sh
bash-3.2$ cat static-routes.sh
#!/bin/bash
sudo route -n add -net 192.168.3.0/24 172.16.254.134
~
• AppleScript contains the following:
do shell script "~/Desktop/static-routes.sh"
• When executing the script from within an AppleScript, by clicking on "Run" button, pop up window saying:
Script Error
sudo: a terminal is required to read the password;
Either use the -S option to read from standard input or
configure an askpass helper
• When exeucuting script from the console without sudo, no additional prompts appear:
bash-3.2$: Desktop jack$ ./static-routes.sh
add net 192.168.3.0: gateway 172.16.254.134
• Here is the snippet from /etc/sudoers:
bash-3.2$ sudo visudo
# root and users in group wheel can run anything on any machine as any user
root ALL = (ALL) ALL
%admin ALL = (ALL) ALL
jack ALL = (ALL) NOPASSWD: /Users/jack/Desktop/static-routes.sh
## Read drop-in files from /private/etc/sudoers.d
## (the '#' here does not indicate a comment)
#includedir /private/etc/sudoers.d
Defaults timestamp_timeout=60
Questions:
• Why this error is showing up, since, I have explicitly added the script to the sudoers file to be executed without password prompt via sudo?
• Which user does AppleScript use to execute the scripts? Is it possible to modify it?
The run a command that requires privileges from AppleScript, you need to specify that by adding the administrator privileges key, as in one of the following:
-- this will presented a standard authorization dialog
do shell script "~/Desktop/static-routes.sh" with administrator privileges
-- this will specifies an administrator account and password
-- (though note, the password will be visible as plain text in the script)
do shell script "~/Desktop/static-routes.sh" with administrator privileges user name XXXX password YYYY
You should not use sudo at the same time you use with administrator privileges; it's unnecessary and creates security holes. However, since you've changed the sudoers file already, you could try this:
do shell script "sudo ~/Desktop/static-routes.sh"
Putting sudo up front like that might cue AppleScript to do the correct thing.
See Technote 2065 for more information.

How do you set the icon for a MacOS app, when you aren't building with Xcode?

I have created a Mac OS app. I am building the app on Ubuntu, and not able to make use of Xcode. When it comes to setting an icon for the app, I am at a loss. How can this be done?
This might appear as a duplicate to this question:
How do I set the icon for my application's Mac OS X app bundle?
However, the solution given here (to simply add the CFBundleIconFile tag in info.plist, with the associated .icns file in the app's Resources directory) does not work for me, nor does it appear to work for some others in that thread. The answer is quite old - is there a newer process? Or, must other steps be taken to get this to work? I am using a program called Image2icon to generate an .icns file - is it that this is not sufficient, and a different process must be taken to generate the .icns?
Good evening, first question with answer, is that once the icon created and placed in the resource your current has not changed? (imagine that in the file info.plist you have named the icon) in this case you may have to delete 2 files to find the new icons below I leave you an applescriipt script that delete them 2 files that the system recreates automatically. in the script you have to change "yourname" and "yourpassword" by your username and password otherwise it will not work. once launched the script the screen will go black and reappear, I put xtrafinder, if you do not use it, erase the line with xtrafinder.
try
set erase to do shell script "sudo find /private -name" & quoted form
of "com.apple.dock.iconcache" user name "yourname" password
"yourpassword" with administrator privileges
do shell script "echo" & quoted form of erase do shell script "sudo rm
-rf -v" & quoted form of erase user name "yourname" password "yourpassword" with administrator privileges
set erase to do shell script "echo" & quoted form of erase & " | sed 's
com.apple.dock.iconcache#com.apple.iconservices#'"
set erase to do shell script "echo" & quoted form of erase
do shell script "sudo rm -rf -v" & quoted form of erase user name
"yourname" password "yourpassword" with administrator privileges
do shell script "sudo killall Dock" user name "yourname" password
"yourpassword" with administrator privileges
do shell script "sudo killall iconservicesagent" user name "yourname"
password "yourpassword" with administrator privileges
do shell script "Sudo killall Finder" user name "yourname" password
"yourpassword" with administrator privileges quit application
"XtraFinder"
do shell script "Sudo open -a /Applications/XtraFinder.app" user name
"yourname" password "yourpassword" with administrator privileges
do shell script "sudo pkill loginwindow" user name "yourname" password
"yourpassword" with administrator privileges
end try

Running AppleScript in Terminal

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

How to mount to a Networked Drive Folder with AppleScript in a Domain

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

Mounting an SMB drive via AppleScript

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/

Resources