Time is tight as usual, so let’s not waste it and get on with the already delayed El Capitan post. 🙂
As some of you already know Apple introduced a new security feature to their latest OS X called System Integrity Protection (SIP). What it basically does is to limit access to sensitive parts of the OS, prevent code injection, etc. This is all fine probably for most users, but limits the possibilities of tweaking the system as well as flexibility of manipulating certain aspects of the OS’s behaviour.
So this brings some inconvenience when you try to automate certain aspects of your daily routine. For example the bless command will not work, you can no longer “empty trash” while a file is still engaged in a process, if disable SIP you can no longer do repair permissions on your system files as this feature has been removed from Disk Utility.
Simply said – if you want the full control over the OS you will have to disable SIP. I am not going in to details on how to do it, there are many articles on internet about that. Here are just few links if you are interested:
Apple’s official article – https://developer.apple.com/library/mac/documentation/Security/Conceptual/System_Integrity_Protection_Guide/ConfiguringSystemIntegrityProtection/ConfiguringSystemIntegrityProtection.html
XtraFinder’s article on how to partially disable SIP – https://www.trankynam.com/xtrafinder/sip.html
or this one for some more customisation – https://www.reddit.com/r/osx/comments/3hv3kk/update_on_rootless_the_configuration_mechanism/
Below you will find two AppleScripts, one for automating the process of repairing file permissions and the other one is for empting your trash.
First the script which does the permission repair. Before using it you will need to download and install the utility from here https://www.firewolf.science/2015/07/repairpermissions-v2-0-cli/
Make sure you follow the installation guidance, read the notes section – it is kind of important.
Alternatively if you do not want to use this utility you may prefer to do it differently by using repair_packages command following this tutorial: http://lifehacker.com/verify-and-repair-permissions-from-the-command-line-in-1741718667
And the script itself, change the necessary bits with your data or change it the way it suits you:
display dialog “Repair Disk Permissions” buttons {“VolumeName 1”, “Volume Name 2”, “QUIT”} default button “QUIT”
if button returned of result = “QUIT” then
quit
else
set diskVol to the button returned of the result as text
tell application “Terminal”
activate
set RP to do script “sudo /usr/local/bin/RepairPermissions \”/Volumes/” & diskVol & “\” “
delay 1
tell application “System Events”
keystroke “YourPassword” & return
end tell
set mainID to id of front window
close (every window whose id ≠ mainID)
repeat until busy of RP is false
delay 1
end repeat
end tell
end if
delay 30
tell application “Terminal” to quit
The second script for empting the trash looks a bit bloated, but as AppleScript has no understanding of “go to” statement /at least I could not find any referral to it, though for some reason this statement is considered a bad practise/ I had no choice but to leave it as it is. Any suggestions are welcome.
As per my previous post regarding AppleScript you will have to adjust some details in the script:
do shell script “sudo nvram SystemAudioVolume=%80” password “YourPass” with administrator privileges
do shell script “defaults write com.apple.loginwindow TALLogoutSavesState -bool false” password “YourPass”with administrator privileges
set trashcontents to quoted form of (do shell script “ls ~/.Trash”)
if trashcontents = “” then
tell application “Finder” to activate
tell application “System Events”
tell process “Finder”
click menu item 13 of menu 1 of menu bar item “Apple” of menu bar 1
end tell
end tell
delay 5
tell application “System Events”
tell process “loginwindow”
activate
click button 2 of window 1
end tell
end tell
else
do shell script “sudo rm -rf ~/.Trash/*” password “YourPass” with administrator privileges
delay 10
tell application “Finder” to activate
tell application “System Events”
tell process “Finder”
click menu item 13 of menu 1 of menu bar item “Apple” of menu bar 1
end tell
end tell
delay 5
tell application “System Events”
tell process “loginwindow”
activate
click button 2 of window 1
end tell
end tell
end if
And that’s it for now, hope this helps not just me, but someone else too 🙂