Script Implementation for Disabling Re-Opening Previous Login

 
Thread Tools Search this Thread
Operating Systems OS X (Apple) Script Implementation for Disabling Re-Opening Previous Login
# 1  
Old 04-20-2012
Script Implementation for Disabling Re-Opening Previous Login

Ok guys,

I'm just getting back to this amongst several other projects, but I thought I'd re-address it. I'm creating the script to disable windows from the previous login under 10.7. In order to do this it seems I need to create the same script for applications that launch and create the associated plist.

Example:
Code:
sudo defaults write com.apple.Safari NSQuitAlwaysKeepsWindows -bool false

I don't know of another way around this, but to create the same script multiple times for the additional applications into a bash script.

Heres my example of the script in totally that I've created:

Code:
#!/bin/bash
# Disable Native Mac Applications from ReOpening from previous login

sudo defaults write com.apple.Safari NSQuitAlwaysKeepsWindows -bool false
sudo defaults write org.mozilla.firefox NSQuitAlwaysKeepsWindows -bool false
sudo defaults write com.google.Chrome NSQuitAlwaysKeepsWindows -bool false
sudo defaults write com.apple.QuickTimePlayerX NSQuitAlwaysKeepsWindows -bool false
sudo defaults write com.apple.Preview NSQuitAlwaysKeepsWindows -bool false
sudo defaults write com.apple.TextEdit NSQuitAlwaysKeepsWindows -bool false
sudo defaults write com.apple.Mail NSQuitAlwaysKeepsWindows -bool false
sudo defaults write com.apple.iTunes NSQuitAlwaysKeepsWindows -bool false
sudo defaults write com.apple.iPhoto NSQuitAlwaysKeepsWindows -bool false
sudo defaults write com.apple.TimeMachine NSQuitAlwaysKeepsWindows -bool false
sudo defaults write com.apple.Preview NSQuitAlwaysKeepsWindows -bool false
sudo defaults write com.apple.iCal NSQuitAlwaysKeepsWindows -bool false
sudo defaults write com.apple.appstore NSQuitAlwaysKeepsWindows -bool false
sudo defaults write com.apple.iWork NSQuitAlwaysKeepsWindows -bool false
sudo defaults write com.apple.AddressBook NSQuitAlwaysKeepsWindows -bool false

# Disable Third-party Mac Applications from ReOpening from previous login
sudo defaults write com.microsoft.Outlook NSQuitAlwaysKeepsWindows -bool false
sudo defaults write com.microsoft.Powerpoint NSQuitAlwaysKeepsWindows -bool false
sudo defaults write com.microsoft.Word NSQuitAlwaysKeepsWindows -bool false
sudo defaults write com.microsoft.Excel NSQuitAlwaysKeepsWindows -bool false
sudo defaults write com.microsoft.Messenger NSQuitAlwaysKeepsWindows -bool false
sudo defaults write com.microsoft.rdc NSQuitAlwaysKeepsWindows -bool false
sudo defaults write com.adobe.Reader NSQuitAlwaysKeepsWindows -bool false

# Will exit with status of last command.

exit

When I run the script, I get the following error:
Code:
sudo: no tty present and no askpass program specified

I'd like to package all this in a bash script or perl script and perform a single shot in terminal.

Moderator's Comments:
Mod Comment Code tags for code, please.

Last edited by Corona688; 04-20-2012 at 03:11 PM..
# 2  
Old 04-20-2012
It means that sudo needs to ask for a password, and can't, because your program isn't run from a terminal.
# 3  
Old 04-24-2012
Think globally instead of writing your preference key to each application domain. Use either the user's GlobalPreferences or the System's GlobalPreferences.

This would be best achieved without the GUI running.
# 4  
Old 04-26-2012
Thanks, xbin. The only GlobalPreferences I'm finding might possibly be an "MCX" file within the user template. Is there another place I should search?

---------- Post updated at 11:42 AM ---------- Previous update was at 11:40 AM ----------

Quote:
Originally Posted by Corona688
It means that sudo needs to ask for a password, and can't, because your program isn't run from a terminal.
Would the following work, Corona688?

$ADMINS ALL = NOPASSWD: LOCATE
# 5  
Old 04-27-2012
I suggest that you read the defaults manual. Focus on the four paragraphs under the DESCRIPTION heading. The file- /Library/Preferences/.GlobalPreferences is modified when you write to the NSGlobalDomain. So,
Code:
defaults write NSGlobalDomain NSQuitAlwaysKeepsWindows -bool 'false'

would write the preference key "NSQuitAlwaysKeepsWindows" and the value to /Library/Preferences/.GlobalPreferences

Note: I did not test this. Use at your own risk. It would be advisable to understand how to remove the preference key should any problems arise.
# 6  
Old 04-27-2012
Quote:
Originally Posted by unimachead
Thanks, xbin. The only GlobalPreferences I'm finding might possibly be an "MCX" file within the user template. Is there another place I should search?

---------- Post updated at 11:42 AM ---------- Previous update was at 11:40 AM ----------



Would the following work, Corona688?

$ADMINS ALL = NOPASSWD: LOCATE
How are you deploying this scripted solution?
Typically, you do not enter "sudo" in a script, as it will require someone enter the password of an administrator. If I'm creating a script like this, I leave off the "sudo" part and just have the basic commands in it.
If I run the script in Terminal.app, I will then use the "sudo" command to run the script, thereby granting my admin access to all the commands in the script. So, script named "defaultchanger.sh" would be run by issuing the command "sudo defaultchanger.sh"

If you are deploying the script remotely, then the deployment solution will likely have a mechanism that will allow it to be run with elevated privileges. Again. No "sudo" in the script would be required.

Good luck! Smilie
# 7  
Old 05-14-2012
Look into Loginhooks ... That will run as root and you do not need the sudo command. It runs at login, and the variable $1 will expand to the user name of the current user, but the script is always run as root. You add a loginhook by a defaults write command to loginwindow.plist I believe, check it out on Google.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Disabling CBC Cipher mode causes login problems

Hi, As part of the security hardening activity in our team, we have to disable CBC mode cipher encryption, and enable CTR or GCM cipher mode encryption. To do this, in sshd_config I comment out these lines : Ciphers aes128-cbc,blowfish-cbc,3des-cbc MACS hmac-sha1,hmac-md5 and add... (9 Replies)
Discussion started by: anaigini45
9 Replies

2. Shell Programming and Scripting

Remove previous line if next & previous lines have same 4th character.

I want to remove commands having no output. In below text file. bash-3.2$ cat abc_do_it.txt grpg10so>show trunk group all status grpg11so>show trunk group all status grpg12so>show trunk group all status GCPKNYAIGT73IMO 1440 1345 0 0 94 0 0 INSERVICE 93% 0%... (4 Replies)
Discussion started by: Raza Ali
4 Replies

3. UNIX for Advanced & Expert Users

Script commad implementation - urgent help

I modified the .profile of a user id to start "script" when the user logs in. When the user logs out, I have added a trap command in the .profile file to capture the exit signal. And in that trap command, I have added the creation of a file called .logout. And in the .logout file, I have added... (3 Replies)
Discussion started by: ggayathri
3 Replies

4. Shell Programming and Scripting

Opening a File with a script

Hi, i am writing a script for exporting tables in oracle, my requirement is to take parameters from the user in a file.. i have to open vi the file,, once user is done with entering the parameters i have to save the file and execite the command exp parfile=exp_2.par .. please let me... (1 Reply)
Discussion started by: saharookiedba
1 Replies

5. AIX

disabling telnet login for root only

Hi, I want to disable telnet login for root only so that other users can telnet? Regards, Manoj (8 Replies)
Discussion started by: manoj.solaris
8 Replies

6. AIX

Problems with disabling remote root login

Hello! I'm going through security checklist for AIX 5.3 and i just can't disable remote login for root through ssh. What i did: - in /etc/security/user i added a line: rlogin = false which works fine when i try to login through telnet - after installation of openSSH i edited... (3 Replies)
Discussion started by: veccinho
3 Replies

7. SCO

Disabling root login

Hy, Coud someone tell me how to disable root login via terminal (only from console should be allowed). There is no ssh installed, only telnet. I created a user which will have permission to su to root, but now i don't know where and what to modify to disable root login? SCO OpenServer 5 ... (1 Reply)
Discussion started by: veccinho
1 Replies

8. Shell Programming and Scripting

Disabling ctrl-Z key inside shell script

Hi I have tried to disable the CTRL-Z key inside a shell(sh) script using the command trap "`echo "Ctrl-Z key disabled"`" 20But I am not able to exit from the script after pressing CTRL-Z key. How to proceed this? Need reply soon (11 Replies)
Discussion started by: suganthic
11 Replies

9. Shell Programming and Scripting

Writing and executing a script in RTR implementation of UNIX

Can anybody provide a complete procedure for writing and executing a script in RTR(real time reliable) implementation of UNIX (0 Replies)
Discussion started by: mahajan.anubhav
0 Replies
Login or Register to Ask a Question