cannot read "account name" from keychain using applescript - applescript

I am not able to read the "account name" from keychain using apple script.
this does not work:
tell app "Keychain Scripting" to get account of "app name"
I am able to read the password from keychain using the following:
local password
set password to do shell script ("security 2>&1 >/dev/null find-generic-password -gl " & quoted form of "app name" & " | cut -c 11-99 | sed 's/\"//g'")
is there a documentation on which commands to use for keychain scripting?

Related

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

`security unlock-keychain` from a bash script

On MacOSX, if I ssh in and run the command:
security -v unlock-keychain -p <password> <keychain_path>
The keychain unlocks and all is well with the world.
If I put that same command into a bash script and run
bash test.sh
I get prompted for the password.
How can I get around this?
You need to explicitly let your script test.sh access your keychain.
Open the Keychain Access
Right click on the private key
Select "Get Info"
Select "Access Control" tab
Click "Allow all applications to access this item"
Click "Save Changes"
Enter your password
Enjoy
Credits: Running xcodebuild from a forked terminal

To create a apple script to change the name of the computer with out prompting for admin

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

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

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