Passing only folder name in embedded scripts

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Hi All,

I seem to have lost all my old rules, :oops: causing me to recreate many of them. I had a rule set up before that would watch a Compress folder for folders. It would then create a DMG archive with the name of the folder and all its contents.

Easy enough, use hdiutil to create it with an embedded script.

The issue I'm running into is when I pass $1 to the volname, it puts the entire path of the folder as the volume name. But when I pass it to the archive name $1.dmg, it works as expected.

Any idea how I can get the volname correct?

It's minor, but it irks me when I mount the DMG, and it's the entire location for the name, not just the name of the folder, which is how I had it before.

I'm open to doing this another way. I can't recall how it was set up before. If I recall correctly, I found someone who made an Automator Script that did this, and I could call that in Hazel.

Any help would be much appreciated.
MikeBowden
 
Posts: 3
Joined: Mon Aug 19, 2013 2:34 pm

$1 is always the full path. Look up the man page for hdiutil. Some arguments expect paths, while some just expect a name.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Correct

The problem I'm having is that I want to pass the name of the folder to -volname, which doesn't require a full path. When I pass $1 to the name of the DMG file, it's only the name of the folder being processed. <--- Not sure why this works.

I'm trying to figure out how to get the same result for the volname as well.

I realize I didn't paste my embedded script in the first post.

hdiutil create -volname $1 -srcfolder . -ov -format UDZO $1.dmg

The above works, but when mounted, the dmg's name on the desktop is the full path of the folder at the time of making it. I can change that to Archive or whatever I want, but I would prefer it to be the name of the folder being processed. The DMG file name itself is only the name of the folder being processed.
MikeBowden
 
Posts: 3
Joined: Mon Aug 19, 2013 2:34 pm

This is more of a general shell scripting issue, but look into the 'basename' command.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support