Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

An AppleScript that may give OS X a speed boost System
My name is Carl Bond. I've made a script (really, it's just a quick hack) to speed up Mac OS X. I hope you like it. Be sure you know what you are doing when you edit and execute this script.

For more information, see my page.
tell application "Terminal"
  do shell script "sudo renice -3 -u YOURUSERHERE" password "YOURPASSWORDHERE" 
    with administrator privileges
  do shell script "sudo renice +9 -u www"
  do shell script "sudo renice +9 -u root"
  
  set finderPID to do shell script "ps -axww | grep '[/]Finder'| awk '{print $1}'"
  do shell script "sudo renice -15 -p " & finderPID
  
  set dockPID to do shell script "ps -axww | grep '[/]Dock'| awk '{print $1}'"
  do shell script "sudo renice -15 -p " & dockPID
  
  set winmanPID to do shell script "ps -axww | grep '[/]Window Manager'| awk '{print $1}'"
  do shell script "sudo renice -15 -p " & winmanPID
  
  set apedPID to do shell script "ps -axww | grep '[/]aped'| awk '{print $1}'"
  do shell script "sudo renice +5 -p " & apedPID
  
  set atsPID to do shell script "ps -axww | grep '[/]ATSServer'| awk '{print $1}'"
  do shell script "sudo renice +5 -p " & atsPID
  
  set pbsPID to do shell script "ps -axww | grep '[/]pbs'| awk '{print $1}'"
  do shell script "sudo renice +5 -p " & pbsPID
  
  quit "terminal"
end tell
[robg adds: Obviously, replace YOURUSERHERE and YOURPASSWORDHERE with the correct information for your account. The referenced page explains what the script does in more detail, but it's basically giving more CPU time to the user's tasks and less to background tasks. I haven't tested the script, and make no claims as to how much this will or will not improve the perceived performance of OS X on your machine. If you do try it and do some numerical before-and-after comparisons, please post your results!]
    •    
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[17,405 views]  

An AppleScript that may give OS X a speed boost | 16 comments | Create New Account
Click here to return to the 'An AppleScript that may give OS X a speed boost' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript that may give OS X a speed boost
Authored by: robmorton on Apr 01, '03 10:59:24AM

Am I missing something. What is the purpose of the tell application "Terminal" part. do shell script is not part of the Terminal's library. do script is, but just looking at the script, I do not see why you would want to open the Terminal instead of doing this in the background. Maybe I am overlooking the obvious though.



[ Reply to This | # ]
An AppleScript that may give OS X a speed boost
Authored by: noblee on Apr 01, '03 11:30:28AM
OK, well all UNIXes have some program to set the priority for each operation. In BSD and Linux and others, this is the nice command. feel free to play with this, but don't change the kernel's nice value! anyway, nice values are in the range [-20...20] with -20 being the highest priority. Basically, if you
sudo nice -n 20 /Applications/Mail.app/Contents/MacOS/Mail
your Mail will be the highest priority task on your box (this is a bad idea, as you might be checking mail and your system might want to use a diskdrive and not be able to as Mail is prioritized). However, if used with restraint, as in this script, it will simply put your programs at a slightly higher priority.

Now, about why he does what he does with the script: you need to tell every method of launching an application or script to be a higher priority. Thus, he needs to tell Finder, Dock, Terminal, etc to be reniced if he wants to get their daughters to run at the new value, e.g., if you launch Word from the Dock, it inherits the nice value from the Dock.

Now, I am hesitant to say this will speed things up on a single user box, though. Nice is a very simple application. Basically, it compares various numbers between every app and whichever has the lowest number is executed first. Most system level processes will still be lower than user processes, thus you should not see a change unless system processes are running in the high values, which is unlikely.

[ Reply to This | # ]

An AppleScript that may give OS X a speed boost
Authored by: robmorton on Apr 01, '03 02:25:22PM

Well, the part I don't get is that tell application "Terminal" is not needed. It just starts for no apparent reason. do shell script ... does not need a Terminal window to be open. Just seemed odd to me. Of course a straight out shell script would be quicker, but these could be added into the Login items by anyone with no Terminal experience.



[ Reply to This | # ]
Yep
Authored by: nick2588 on Apr 04, '03 12:38:56AM
Yes, the tell block is unnessessary in this script, because do shell script is NOT functionality provided by Terminal. The functionality is provided by Standard Additions, and therfore you can use do shell script without a tell block of any kind.

[ Reply to This | # ]
Yep Confirmation
Authored by: nick2588 on Apr 04, '03 12:41:04AM
From http://www.apple.com/applescript/terminal/:

"Note that it is not necessary to use the Terminal application to execute shell scripts. The "Do Shell script" command is part of the pre-installed Standard Additions scripting addition and can be used to communicate with the UNIX shell directly."

[ Reply to This | # ]
An AppleScript that may give OS X a speed boost
Authored by: schnarr on Apr 01, '03 12:16:12PM

I have something similar running in a startup shell script... No user renices, tho, just some renicing of PIDs.

Personally, I'd never renice root to be _SLOWER_ like this does, but then again TCP/UDP speed is much more important to me than fancy GUIs because my mac is primarily a network server. Since nearly all the networking commands I use are running as root, this would affect me a lot (inetd, ssh, VNC primarily, as well as ipfw). Since I'm not running a web server, www doesn't exist (running a web server is pointless, because port 80 is blocked by my ISP... ok, could run it on, say, port 8000, but nobody will find it there).

A nice (but non-'nice') way of boosting tcp network performance can be added into this script, if you wanted to: Apple uses very conservative default values for several kernel parameters, which can be upped using the following commands as root:
sysctl -w kern.ipc.maxsockbuf=2097152
sysctl -w net.inet.tcp.sendspace=262144
sysctl -w net.inet.tcp.recvspace=262144

You could add this to your script underneath the third do (under tell application "Terminal") add in
do shell script "sudo sysctl -w kern.ipc.maxsockbuf=2097152"
do shell script "sudo sysctl -w net.inet.tcp.sendspace=262144"
do shell script "sudo sysctl -w net.inet.tcp.recvspace=262144"

I'm not sure if that offsets any losses from renicing root, though...



[ Reply to This | # ]
An AppleScript that may give OS X a speed boost
Authored by: hagbard on Apr 05, '03 07:35:09AM

does anyone know where those many settings would be discussed/documented ?
I've tried tweaking them myself before, using their respective names to guess what that would do, but I'd love to have some definite documentation on them...

thanks



[ Reply to This | # ]
An AppleScript that may give OS X a speed boost
Authored by: mervTormel on Apr 01, '03 01:29:03PM

why not just dump all those shell commands into a single shell script and invoke it?!

a lot of wasted calls to 'do shell script' in the hint above.



[ Reply to This | # ]
Holy runaway processes, Batman!
Authored by: porkchop_d_clown on Apr 01, '03 03:57:08PM

-15?!? I'm sorry, but wouldn't a nice -1 do?

I'm not sure about OS X, but on many Unixes, running a process at less than -5 will interfere with interrupts and hardware devices...

---
Everyone loves a clown, but no one will lend him money!



[ Reply to This | # ]
An AppleScript that may give OS X a speed boost
Authored by: rpitcairn on Apr 01, '03 10:04:17PM

I wanted to try this out and downloaded the script and edited in my user name and password. However when I ran it I got this error message each time-

Terminal got an error: renice: 70:
getpriority: no such process.

Was anyone else able to try it? And what is this error about?



[ Reply to This | # ]
An AppleScript that may give OS X a speed boost
Authored by: jmcgready on Apr 02, '03 04:08:13AM

the problem, at least for me, was solved when
I got rid of the second renice command -
the one for user www....

then things ran swimmingly....



[ Reply to This | # ]
An AppleScript that may give OS X a speed boost
Authored by: michaelfr on Apr 02, '03 08:59:26AM

I noticed the post warning about using a -15 in the renice command as possibly interfering with the system. While I don't think I would change the priority for system-level processes, I've been doing this with my own processes for awhile now.

I've been using the following code for over a year on my OS X system and have had no problems with it whatsoever. I've run this on a G3/400 and on my G4/800, using OS X versions from 10.1.5 thru 10.2.4, with no problems:

do shell script "sudo renice -15 -u USER_NAME password PASSWORD with administrator privileges

It does seem to increase performance without incident.

Thanks,

---
Michael Frankel
The Database Factory
(818) 508-7090 / Cell (888) 291-3419



[ Reply to This | # ]
An AppleScript that may give OS X a speed boost
Authored by: rpitcairn on Apr 02, '03 10:32:09PM

I tried this but only get the response that "Command not found". Tried different ways of formatting the sentence, like where to put the quote marks as the way you posted it said there was a quote missing. Anyway, can't get it to work.



[ Reply to This | # ]
An AppleScript that may give OS X a speed boost
Authored by: pink on Apr 04, '03 06:00:04AM

actually, I don't see why not just type
sudo renice -15 -u USERNAME
in the terminal. This is remembered between logouts, so it just has to be repeated after reboots..

cheers, pink



[ Reply to This | # ]
An AppleScript that may give OS X a speed boost
Authored by: rpitcairn on Apr 02, '03 10:50:30PM

I tried this last script by Michael but am not knowledgeable to know how to do it correctly.
I finally got a response in Terminal after tweaking the command a bit. Here is what I put it and what I got back:
[USERNAMESComputer:~] USERNAME script "sudo renice -15 -u USERNAME" password "PASSWORD" with administrator privileges
Script started, output file is sudo renice -15 -u USERNAME.

Of course I have edited out my name and password so you can assume I put in the correct ones. My question is if the response about the script started means that I was successful in doing it?



[ Reply to This | # ]
An AppleScript that may give OS X a speed boost
Authored by: clabough on Aug 19, '03 04:26:39PM

sudo renice -15 -u USER_NAME
is all you would enter in the Terminal. The notation above is for if you are making an Applescript.



[ Reply to This | # ]