Page 1 of 2

Ejecting DMGs

PostPosted: Sat Aug 25, 2007 4:17 pm
by NightOne
I'm tired of manually ejecting DMGs after installing applications so in the spirt of Office Space, don't think I want to do it anymore. :D

However, haven't been able to figure out how to get this rule done yet. Basically, I want to leave the DMG wherever it is but Eject it 1 hour after it was opened.

Ideas anyone?

PostPosted: Sun Aug 26, 2007 4:52 pm
by IDontDoWindows
I'm playing around with this, but haven't found a solution.

What I have found:
1. it looks like you'd need some way of watching the computer, as that's where new volumes show up and Hazel can't watch the computer "folder".

2. selecting the dmg on the desktop and using "get properties of (selection as alias)" in applescript didn't result in any info I could use for this.

3. using mdls in Terminal, however, resulted in two fields kMDItemLastUsedDate and kMDItemUsedDates which might be helpful. (note that I used mdls on the actual dmg file and not the opened dmg volume. the opened dmg volume didn't return any info I thought could be useful.

PostPosted: Mon Aug 27, 2007 11:39 am
by Mr_Noodle
Interesting. Well, I'm not sure if this will work so try this at your own risk.

There's the /Volumes folder. It's not visible in Finder but it's where disks are usually mounted by Finder. You can have Hazel monitor this folder. To get to it in the open dialog, type in slash (/) which will bring up a little panel where you can type in the full path. Just type /Volumes and it should get added.

Once it's monitored, I think Date Added would work here if you only care about how long it's been around. The mount entries appear and disappear as the disk/disk image is mounted and unmounted.

A few things to look out for:
- Do not use any rules that do "Run rules on folder contents". Basically, every file on every drive is accessible from this point (including your boot drive). Descending down into the folders can cause havoc.
- There is an entry here for every mounted drive, this includes external hard drives, like your boot drive. Whatever script you write to do the ejecting should check to make sure it's not ejecting drives you do not want it to.

Before even hooking up Hazel to this, I'd make sure the script was working properly.

PostPosted: Wed Sep 05, 2007 7:14 pm
by NightOne
None of you "hacker" types got this done yet so us lazy users can use it? :D

PostPosted: Thu Sep 06, 2007 11:42 pm
by IDontDoWindows
That's funny... I've been checking this thread off and on to see what you came up with ...
:lol:

PostPosted: Fri Sep 07, 2007 11:06 am
by IDontDoWindows
Actually, I keep playing with this and coming up with nothing. Hazel's Date Added doesn't give you a time factor. I had it watch the Volumes folder anyway, looking for anything whose extension was 'dmg' and whose date added was today, telling her to growl me. Nada.

I'm just not sure how you get this done. It seems like it must be conceivably possible, but not actually possible.

PostPosted: Fri Sep 07, 2007 3:32 pm
by Mr_Noodle
The dmg files don't appear in Volumes, but the actual mounted directory. Basically, whatever appears on your Desktop/Finder sidebar is actually located in the /Volumes directory.

The problem is differentiating these directories from those of your more permanent drives (like your boot drive). But you can at least see when stuff is mounted/unmounted.

PostPosted: Thu Sep 27, 2007 2:35 pm
by NightOne
IDontDoWindows wrote:That's funny... I've been checking this thread off and on to see what you came up with ...
:lol:


Me too. :D

Still am as a matter of fact.

PostPosted: Thu Sep 27, 2007 11:37 pm
by gerbercj
I've only been using Hazel for about 20 minutes, but I've got some basic ideas:

1) The folder to monitor is /Volumes. You can use Finder and "Go / Go to Folder..." to manually open the folder. Once you've done that, add it to the Sidebar. That will allow you to easily access it in Hazel.
2) Create a new rule called something like "Auto-eject DMG".
If all of the following conditions are met
> Kind is not folder
> Date Last Matched is not in the last 1 hour
Do the following:
> Run shell script

The shell script should run "hdiutil detach /Volumes/", followed by the name of the identified object. I don't know how to do that part yet.

Maybe this will get someone most of the way? I haven't ruled out that I'm way off here.

PostPosted: Fri Sep 28, 2007 12:17 am
by gerbercj
Follow-up... I'm a little closer. I have learned that my "Date Last Matched" setting is wrong. I don't have a fix for this yet.

Here's some AppleScript for the actual eject action:

Code: Select all
on hazelProcessFile(infile)
   tell application "Finder" to set inFileName to name of infile as string
   do shell script ("hdiutil detach '" & inFileName & "'")
end hazelProcessFile

PostPosted: Fri Sep 28, 2007 12:38 am
by gerbercj
Last post... really! I needed to replace "Date Last Matched" with "Date Added". Here's the final version:

If all of the following conditions are met
> Kind is not folder
> Date Added is not in the last 1 hour
Do the following:
> Run AppleScript eject.scpt

eject.scpt:
Code: Select all
on hazelProcessFile(infile)
   tell application "Finder" to set inFileName to name of infile as string
   do shell script ("hdiutil detach '" & inFileName & "'")
end hazelProcessFile


Let me know if this works for folks... I haven't tested much as I need to get to bed.

PostPosted: Thu Oct 04, 2007 8:14 pm
by blodwyn
gerbercj wrote:Last post... really! I needed to replace "Date Last Matched" with "Date Added". Here's the final version:

If all of the following conditions are met
> Kind is not folder
> Date Added is not in the last 1 hour
Do the following:
> Run AppleScript eject.scpt

eject.scpt:
Code: Select all
on hazelProcessFile(infile)
   tell application "Finder" to set inFileName to name of infile as string
   do shell script ("hdiutil detach '" & inFileName & "'")
end hazelProcessFile


Let me know if this works for folks... I haven't tested much as I need to get to bed.


You can also do this by running an Automator workflow containing a single "Eject Disk" action. A quick test seemed to work OK

PostPosted: Thu Oct 18, 2007 11:19 pm
by NightOne
I can't seem to get mine working. I made a simple Automator workflow which ejects a a DMG and the following rule:

Image

However, the outlined part doesn't seemed to be gettting respected all the time.

During testing I opened some DMGs and they close immediately. I have some that stay do not close immediately. I manually close them and on a subsequent go-around they get closed immediately. I then open one that previously got closed immediately mutliple times and now it stays open. I haven't found any rhyme or reason to it yet. I did a get info and the Last opened time is within a minute on all of them.

Currently using Hazel 2.0.2 (v358)

Any ideas?

PostPosted: Tue Oct 23, 2007 1:34 pm
by NightOne
Well part of this can definitely be explained as follows:

When I look at the .dmg file on the disk, I see the following in the Get Info

Image

However, when I look at the mounted DMG, I see:

Image

Which would explain why this won't work.

I don't see anything in the mounted disk image get info that I could used to determine how long it has been open. :(

PostPosted: Tue Oct 23, 2007 7:55 pm
by Mr_Noodle
I think there is some confusion here about the difference between the disk image and it's mounted folder.

Volumes does not contain disk images (the dmg files). When you mount the dmg files, the folder is mounted under Volumes. Note that this is not the dmg file itself so checking any dates on the dmg file won't help since they are not located in the Volumes folder (and aren't the files you care about anyways).

To do what I think you are trying to do, use "Date Added" on the mounted volume. The mount points appear when the disk image is mounted so it should reflect what you want (the date when it was mounted) since from the view of the Volumes folder, those folders were just added. I believe the Eject Automator action also operates on the volume, not the disk image file, so it should work.

So, in short, just change "Date Last Opened" to be "Date Added". Let me know if that works out.