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

10.5: Use launchd to restart crashed apps System 10.5
launchd in 10.5 introduces a couple of new flags to the launchd config plists, specifically KeepAlive (bool or dict) and SuccessfulExit (bool, as child of KeepAlive dict). Using these flags, you can tell launchd to launch an application and automatically restart it if it crashes, but NOT if it exits cleanly. This previous hint showed a somewhat different approach to accomplish the same thing.

Using my company's flight management software as an example, you would end up with the following LaunchAgent .plist file, which I put in my home Library/LaunchAgents folder:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>KeepAlive</key>
	<dict>
		<key>SuccessfulExit</key>
		<false/>
	</dict>
	<key>Label</key>
	<string>com.frontierflying.flightmaster</string>
	<key>ProgramArguments</key>
	<array>
		<string>/Users/Shared/FlightMasterStandalone/FlightMaster2004.app/Contents/MacOS/EXE</string>
	</array>
</dict>
</plist>
I made the inital file using Lingon, and then edited it using Propertylist editor to add the KeepAlive dict/SuccessfulExit key set. The program arguments string needs to be the path to the actual executable inside the app bundle, not just to the .app (assuming it is a bundle app) as shown.
read more (178 words)   Post a comment  •  Comments (3)  
  • Currently 3.50 / 5
  You rated: 5 / 5 (6 votes cast)
 
[22,444 views]  View Printable Version
10.5: A python script to work around a sleep issue System 10.5
After installing Leopard, my iMac would no longer auto sleep. It worked flawlessly in Tiger. I searched google and found many others having similar problems. I found many different fixes, such as removing the PowerManagement plist file, unplugging all devices, and not running certain widgets or programs. However, no matter what I did, it would not auto sleep. It would stay asleep if I manually put it to sleep.

I called Apple and was on the phone with them for about two hours before they said it is probably a hardware problem, thanks for calling. After all that hassle, I decided to see if AppleScript could put it to sleep, and it did. Once I found that out, I just wrote a python program that keeps track of how long the screen saver is running. Using that, it determines if the system has been unused for the period the user set in system preferences for machine sleep.
import sys, os, shutil, filecmp, string, datetime, time

# initalize some variables
cronPeriod = 1
sleepFile = "/Library/Preferences/SystemConfiguration/com.apple.PowerManagement.plist"
saverFile = os.path.join(os.getenv("HOME")) + '/Library/Preferences/ByHost/com.apple.screensaver.0016cb98e9e2'
trackingFile = os.path.join(os.getenv("HOME")) + '/var/sleepTracker'

f = open(sleepFile, "r")
useNextLine = 0
for line in f.readlines():
  if useNextLine == 1:
    useNextLine = 0
    timeLine = line.strip()
  if line.strip() == "<key>System Sleep Timer</key>":
    useNextLine = 1
f.close()

sleepTime = timeLine.strip('<integer>')
sleepTime = sleepTime.strip('</')
sleeepTime = int(sleepTime)

screensaverTime = os.popen("defaults read " + saverFile + " idleTime")
screensaverTime =  screensaverTime.read()

sleepTime = int(sleepTime) * 60 - int(screensaverTime)
if sleepTime < 0:
  sleepTime = 0


########################################
# Begin function definations
######################################## 
# checkFiles is the function that checks the times
# of the tracking file

def clearFile():
  if os.path.exists(trackingFile):
    os.remove(trackingFile)
  cmd = "touch " + trackingFile
  os.system(cmd)

def compareTimes():
  endLine = ""
  currentTime = time.mktime(datetime.datetime.now().timetuple())
  currentTime = str(currentTime).split('.')[0]

  f = open(trackingFile, "r")
  data = f.read()
  f.close()
  lines = data.split("n")
  lastRunning = lines[len(lines)-2]
  lastRunning = lastRunning.split('.')[0]

  if lastRunning == "":
    print "last time is: " + lastRunning
    return

  difference = int(currentTime) - int(lastRunning)
  print time.localtime()
  print "difference between current time and last time saver was found running is: ", difference
 
  cronPeriodSec = int(cronPeriod * 1.5 * 60)
  print time.localtime()
  print "cron period is: ", cronPeriodSec

  if difference > cronPeriodSec:
    print time.localtime()
    print "difference is greater - need to clear file"
    clearFile()

def wantSleep(currentTime):
  f = open(trackingFile, "r")
  data = f.read()
  f.close()
  lines = data.split("n")
  firstRunning = lines[0]
  firstRunning = firstRunning.split('.')[0]

  if firstRunning == "":
    #print "firstRunning was blank"
    return

  print "current time is: ", currentTime, " first time is: ", firstRunning
  difference = int(currentTime) - int(firstRunning)
  print time.localtime()
  print "difference between now and first time screensaver was on is: ", difference
  print "comparing against: ", int(sleepTime) 

  if difference >= sleepTime:
    print time.localtime()
    print "sleep is desired" 
    aplcmd = 'tell app "Finder" to sleep'
    cmd = "/usr/bin/osascript -e " + "'" + aplcmd + "'"
    print time.localtime()
    print cmd
    os.system(cmd)
 
##############################################
# End function definations
#############################################

#check if the screensaver is running:
cmd = "ps -e | grep ScreenSaverEngine | grep -v grep"
result = os.system(cmd)

#print "remove the following line to run for real"
#result = 234

if result != 256:
  print time.localtime()
  print "Screen Saver is running"
  compareTimes()

  currentTime = time.mktime(datetime.datetime.now().timetuple())
  currentTime = str(currentTime).split('.')[0]
  f = open(trackingFile, 'a')
  f.write(currentTime + "n")
  f.close

  wantSleep(currentTime)

else:
  print time.localtime()
  print "Screen Saver Not running"
  clearFile()

sys.exit(1)
I put this in cron to run once a minute and it has been working very reliably. Note: I didn't make it robust enough to find the screensaver preferences file. I hard-coded it to mine, so if anyone wants to try it, you would need to update the numbers at the end of the saverFile value.

[robg adds: I haven't tested this one.]
  Post a comment  •  Comments (3)  
  • Currently 2.83 / 5
  You rated: 3 / 5 (6 votes cast)
 
[8,401 views]  View Printable Version
10.5: Browse an SMB Network Drive in Leopard System 10.5
As of version 10.5.1, you may be able to connect to an SMB network drive, but you may not be able to browse the contents of any shared folders on the drive. Here's how you can force Finder to display the folder contents.

Connect to your network drive using the normal methods -- either Command-K or the Connect to Server option on the Go Menu. Once Finder has connected to the drive, open Terminal and type the following command:
sudo smbclient -L NETWORK_DRIVE_NAME
Replace NETWORK_DRIVE_NAME with the Windows name for your network drive. Next restart the Finder by typing sudo killall Finder. Wait for Finder to restart -- this should only take a moment -- and then run the above command again.

Open a Finder window, and click the name/IP address of your network drive. You should now be able to browse the contents of your drive.

[robg adds: I can't confirm either the problem or the solution.]
  Post a comment  •  Comments (2)  
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[24,340 views]  View Printable Version
10.5: Open print/fax prefs from Print dialog in some apps System 10.5
If you have the Print dialog already open in some Apple applications (e.g. Safari, Mail, TextEdit), pressing Command-P will open Print and Fax preferences in System Preferences.

It seems to work inconsistently among Apple's programs. For example, it works in Safari and Mail, but in iCal, you have to hit Continue and then cancel the print dialog for the System Preferences to appear. In Preview, it seems that doing Command-P when the print dialog is already open sends the current document to the printer. So this behavior is inconsistent among Apple apps, and doesn't work in the non-Apple apps I've tried (Word, etc.).
  Post a comment  •  Comments (2)  
  • Currently 2.67 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[4,898 views]  View Printable Version
10.5: Move apps between spaces with the app switcher System 10.5
Grab a window's title bar and then use Command-Tab to switch to an application which you know resides in another space -- hey presto! The clicked window is transported to the new space for you as soon as you release Command-Tab.

If, like me, you keep Safari in one space and iTunes in another, this is handy for when you're watching a movie in iTunes and want to watch while surfing. Just grab the movie window and switch to Safari and you're done. It just works, as I expected it would when I had the idea to try. The grabbed window even retains focus, so it's just a more intuitive way to switch spaces without having to reach all the way across the keyboard to hit Control and the arrow keys or numbers.
  Post a comment  •  Comments (7)  
  • Currently 1.33 / 5
  You rated: 1 / 5 (3 votes cast)
 
[15,383 views]  View Printable Version
10.5: Open new Finder or Safari window in current space System 10.5
Spaces can be very useful, but there are some behaviours that can irritate or confuse. For example, if you switch to an application that has inactive windows in another space, you are taken to the space with an inactive window. This is usually helpful, but in some cases, especially if you use multiple spaces with one or two dev apps running in each, and need to go to the web via Safari to look something up, or open a Finder window to browse the local filesystem, it is not exactly what you want.

Fortunately, these two apps have New Window commands in their Dock menus. So, if you are in a space with Coda and a separate Terminal window or two, and need to open a Finder or Safari window but don't want to move spaces, simply choose the New Window command from the Dock menu of the appropriate app, and a new active window opens in the current space.

It's possible other apps have this command also (for example, TextMate does, but it opens the new window as inactive in the current space), so check out the Dock menus of your apps and see if this can help you enjoy Spaces even more.
  Post a comment  •  Comments (7)  
  • Currently 2.63 / 5
  You rated: 1 / 5 (8 votes cast)
 
[16,411 views]  View Printable Version
10.5: Clear Download stack via an overlay icon System 10.5
I hate how stacks only allow you to drag one file at a time out of them, so I decided to combine some earlier hints into a solution. By combining the overlay icons discussed here with this AppleScript, I've created an overlay icon for the Downloads folder [84KB download] that actually performs a helpful function: it empties the stack if you select it!

To add the ability to sort by date modified as well as by name, open Terminal, cd to the correct folder and then, assuming you haven't changed the name of the AppleScript, just type this:
touch -mt 202001010101.01 " Downloads .app"
[robg adds: I haven't tested this one -- note that this is different than this hint, which uses an Automator action to clear a stack. (The comments to that hint explain how to use the Automator action to similar effect as shown here.)]
  Post a comment  •  Comments (0)  
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[12,266 views]  View Printable Version
10.5: 'Right size' columns in Open and Save dialogs System 10.5
When viewing an Open or Save dialog in column view mode, try a control-click on the column separator at the bottom of a column to get the choices of Right Size this Column, Right Size All Columns Individually, or Right Size All Columns Equally. Each does what you would expect.

[robg adds: Very oddly, you won't find this contextual menu in the Finder, only in the Open/Save dialogs.]
  Post a comment  •  Comments (8)  
  • Currently 2.75 / 5
  You rated: 3 / 5 (4 votes cast)
 
[7,201 views]  View Printable Version
10.5: View text clippings in Quick Look System 10.5
I've been frustrated with Apple's treatment of text clippings; they seem neglected. For example, you can't select and copy the text when you view them in Finder. And with the release of 10.5, I was dismayed to see that Quick Look could not view text clippings either.

However, I stumbled across a plug-in for doing just that! All the credit goes to the original developer. It also supports picture clippings, though I haven't tested that.

[robg adds: A short history of copying from text clippings: Until 10.3, you couldn't do this at all. When 10.3 came out, you could copy from clippings -- but only the entire clipping. In 10.4, you could actually select some text from a clipping and copy it, even though you couldn't see exactly what was selected on-screen. In 10.5, though, we're back to the 10.3 behavior: Command-C will only copy the entire clipping, even if you first make an invisible selection.]
  Post a comment  •  Comments (11)  
  • Currently 2.33 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[7,119 views]  View Printable Version
10.5: Monitor Time Machine activity via GeekTool System 10.5
I've been having some problems getting Time Machine to work properly, and I've grown tired of opening the Time Machine System Preferences pane just to see if Time Machine executed when it was supposed to. Using GeekTool -- which runs well on Leopard -- I'm now able to get a regular status report effortlessly, which has eased my mind considerably since I now know Time Machine is working properly.

Create a new shell entry in GeekTool, and enter the following command: This scans the system log file for the last three entries from backupd, displaying them on the desktop. Use whatever refresh value you'd like; 10 minutes is good enough for me.

I'm also able to monitor remote Time Machine activity from other computers backing up to a local disk connected to my computer. Just use this command in GeekTool: If you've set up passwordless ssh login, you're golden.

[robg adds: I haven't tested this one.]
  Post a comment  •  Comments (12)  
  • Currently 2.80 / 5
  You rated: 2 / 5 (5 votes cast)
 
[30,836 views]  View Printable Version