Help please: Disk Utility as a login item

I have a hard disk w/ 3 partitions, 2 of which I usually want to keep unmounted, so when I start up I open Disk Utility and unmount them. Definitely a task to be automated, no?

If I list Disk Utility as a Login Item, the app activates OK on startup but its window isn’t visible, so I have to type Command-N or select New Window from the File menu. I tried varying the order of my Login Items, but that didn’t solve the no-window problem. Disk Utility is the frontmost app but has no window.

I made a script to open the app (actually 2 apps that I like to have open when I startup), with Disk Utility as the last app to open. Then I listed the script as a Login Item. Same result.
[BTW, this no-window problem only occurs at startup. If I run the script manually, Disk Utility opens normally w/ a nice normal window]

Then I came up w/ a System Events way to open the New Window menu item. That’s great but how can I make it conditional, so it opens a new window only if there isn’t one already open?

Finally, I was hoping eventually to script Disk Utility to unmount those 2 disk partitions I mentioned at the top, but am I correct in understanding that Disk Utility is not scriptable?

Here’s my script; the Disk Utility part is only the last 8 lines. I’m a beginner so pls be gentle. :confused:

to |set position| for w to {x, y}
	set {l, t, r, b} to w's bounds
	set w's bounds to {x, y, x + r - l, y + b - t}
end |set position|

activate application "Internet Connect"
tell application "System Events"
	tell process "Internet Connect"
		click menu item "Internal Modem" of menu "Window" of menu bar 1
	end tell
end tell
|set position| for application "Internet Connect"'s window 1 to {672, 427}
tell application "Disk Utility"
	activate
	tell application "System Events"
		tell process "Disk Utility"
			click menu item "New Window" of menu "File" of menu bar 1
		end tell
	end tell
end tell

Model: PowerBook G4
AppleScript: 1.10.6
Operating System: Mac OS X (10.4)

Ciao longjump,
sorrily you are right: Disk Utility is one of those Apple apps that are not scriptable (shame on them :wink: ).
What should help you are the unix commands diskutil and hdiutil which do all the jobs Disk Utility does and much more. You can check their functions typing “man diskutil” or “man hdiutil” in the Terminal. Once you have found the commands that do your job you can then implement them in your Script with “do shell script your_command
I ran in a similar problem some time ago and it worked, unfortunatedly I’m not sitting in front of my Mac now - with a search you should find some examples in this forum too.

Good scripting
Farid

Why not do something like this?

tell application "Finder"
	eject (every disk whose name is not "<your boot partition>")
end tell

Haven’t tested it with a partitioned drive, but I have used this in the past for mounted afp volumes.

I think longjump is looking for a solution to keep one or more partitions active, while the Finder unfortunatedly will eject all partitions of a choosen volume (as he does if you drag one partition into the Trash).
I have this little script which uses diskutil to mount/unmount single partitions, maybe playing around with the code longkump might find a solution:

property diskInfoList : {}
global theID

tell application "Finder"
	set mountedDisks to name of every disk
end tell

set diskInfoList to {}
set chooseList to {}
set theDisks to (do shell script "diskutil list")
set c to count of paragraphs of theDisks
repeat with i from 1 to c
	if word 2 of paragraph i of theDisks = "Apple_HFS" then
		set end of diskInfoList to {nameDisk:(word 3 of paragraph i of theDisks), deviceName:(last word of paragraph i of theDisks)}
		set end of chooseList to (word 3 of paragraph i of theDisks)
	end if
end repeat
set choice to (choose from list chooseList with prompt "Scegli il disco da dis/attivare:") as string

searchID(choice)

mountUNmount(choice, theID, mountedDisks)

on searchID(choice)
	repeat with i from 1 to count of diskInfoList
		if (nameDisk of item i of diskInfoList) = choice then
			set theID to (deviceName of item i of diskInfoList)
			exit repeat
		end if
	end repeat
	return theID
end searchID

on mountUNmount(choice, theID, mountedDisks)
	if choice is not in mountedDisks then
		display dialog "Vuoi attivare il disco \"" & choice & "\" ?" buttons {"Annulla", "OK"} default button 2 with icon 1
		if button returned of the result = "OK" then
			set theCommand to "diskutil mount " & theID
			do shell script theCommand
		end if
	else
		display dialog "Il disco \"" & choice & "\" è già attivo." & return & "Vuoi disattivarlo?" buttons {"Disattiva", "Annulla"} default button 2 with icon 2
		if button returned of the result = "Disattiva" then
			try
				set theCommand to "diskutil unmount " & theID
				do shell script theCommand
			end try
		end if
	end if
end mountUNmount

Good scripting
Farid

PS: let me know if you need a translation of the dialogs :wink:

Thanks y’all for the suggestions; hmm, I guess I’ll try Jacques’ idea first. Before I do though: I’m pretty unix-ignorant, plus new to OS X, plus always been a little skittish messing around at the shell level, wondering if I might mistype a character and cause something disastrous. So pls indulge me in a few safety questions: Am I correct in understanding that first_partition_name and second_partition_name are the partitions that I want to unmount? BTW this is probably irrelevant but I’ll mention just in case, regarding the order in which the 3 partitions come up in Disk Utility’s window: the partition that I keep mounted comes up in between the 2 partitions that I unmount. Also, perhaps worth mentioning: these 3 partitions are on an external HD and the partition that stays mounted is the startup volume in this scenario; so my internal HD is a 4th volume that also must remain mounted (see outline below).

Ext. HD:
Partition 1: to be unmounted
Partition 2: startup volume
Partition 3: to be unmounted
Int. HD: to remain mounted. Not partitioned, is just one volume.

Thanks!
longjump

Hey Jacques, your script worked. Thanks! Thanks to you other responders too.

Two problems cropped up not long after I ran your script–unrelated, I hope?

  1. In my “Universal Access” Sys. Pref. pane, the checkbox “Enable access for assistive devices” unchecked itself.
  2. My finder now crashes every time I try to drag an alias into a new folder. Or it may be more accurate to say the finder windows reset themselves as if I’ve just restarted the puter. Doesn’t seem to harm any ongoing operations in other apps, but it’s quite annoying.

I repaired all my disks and permissions in Disk Utility, but that had no effect. I have no idea what’s happening in the script; it’s over my head. So I’m not saying it caused the problem, just asking. However after some trial runs there does seem to be a direct correlation between the running of the script and the unchecking of that “assistive devices” checkbox. … Oops, waidaminnit, I just tried it again and the checkbox stayed checked. Hmmm…

set ID_Disks to paragraphs of (do shell script "/usr/sbin/diskutil list | /usr/bin/grep '\\(\\d2 160G - 11G part.\\|\\d2 160G - Part. 3\\)' | /usr/bin/awk '{print $NF}'")

repeat with thisitem in ID_Disks
	do shell script "/usr/sbin/diskutil unmount " & quoted form of thisitem & " > /dev/null 2>&1 &"
end repeat

Thanks again
longjump