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


Click here to return to the 'Here's a script to Help' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Here's a script to Help
Authored by: kb5ql on Jan 22, '03 07:39:47PM

I have written the perl script below - it quits all of my open applications, then it unmounts any ejectable disks. You can place this in your ~/Library/Scripts folder and chmod 755 it to run it from the menubar (assuming you have the ScriptMenu.menu installed there). The reason for quitting all applications is so you don't get a "file in use" error when attempting to unmount. You can customize it by adding applications to the excluded_list array.

name the file with a *.pl extension


#!/usr/bin/perl -w

###############################################################################
#
# File: goHome.pl
#
# Function:
#
# Author(s): MGJ
#
# Copyright: Copyright (c) 2003 MGJ
# All Rights Reserved. Please keep the header intact
#
# Source: Started anew.
#
# Notes: This quits all open applications - except those in the excluded list
# and then unmounts all network volumes -
# Finally - it prompts you if you want to put the computer to sleep
#
# Change History:
# 1/16/03 Started source
#
#
##############################################################################
use strict;

my (%appList,$theAppString);
my $osascript_name = "/tmp/goHome.scpt";

my @excluded_list = ("Script Editor","Microsoft Database","Show Desktop","PTHClock");

#grab all command output
my @output = `ps -xwwwwo command`;

foreach my $line(@output)
{
if ($line =~ m|^/Applications/.+/([^-]+)( -psn.+)?|)
{
my $match = $1;
if($match =~ /(.+)\s+/) { $match = $1; }
#print "$match\n";
$appList{$match} = "t";
}
}

foreach my $element (keys %appList)
{
# print "testing $element\n";
foreach my $excluded(@excluded_list)
{
if ($element =~ /$excluded/)
{
#print "i found a match -> $excluded\n";
#set flag to false (don't quit these apps);
$appList{$element} = "f";
}
}
}
foreach my $element2 (keys %appList)
{
if ($appList{$element2} ne "f")
{
if ($theAppString)
{
$theAppString .= ",\"$element2\"";
}
else
{
$theAppString = "\"$element2\"";
}
}
}
(my $osascript = <<"eoj") =~ s/^\t+//gm;

property theApps : {$theAppString}

repeat with x in theApps
set theApp to x
tell application theApp
quit
end tell
end repeat

tell application "Finder"

set startupDisk to name of startup disk
set theDisks to every disk whose (name is not startupDisk and ejectable is true)
repeat with x in theDisks
set diskName to name of x
--display dialog diskName buttons {"Cancel", "Space", "Return"}
try
eject disk diskName
end try
end repeat
end tell



tell application "Finder"
display dialog "Do you want to sleep?" buttons {"Cancel", "Yes"}
sleep
end tell

eoj

#print "$osascript";


open(OUTFILE,">$osascript_name");
print OUTFILE $osascript;
close(OUTFILE);

system("osascript $osascript_name");



[ Reply to This | # ]
Need to modify eject volumes (possibly)
Authored by: kb5ql on Jan 22, '03 07:44:33PM

I forgot to mention that you will probably need to modify the applescript (located at the bottom of the script) if you have volumes (other than the startup volume), you don't want unmounted. This isn't a problem in my setup since I want ALL of my volumes unmounted (including my external firewire drive).



[ Reply to This | # ]