Page 1 of 1

Passing only folder name in embedded scripts

PostPosted: Sun Mar 28, 2021 1:24 pm
by MikeBowden
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.

Re: Passing only folder name in embedded scripts

PostPosted: Mon Mar 29, 2021 10:17 am
by Mr_Noodle
$1 is always the full path. Look up the man page for hdiutil. Some arguments expect paths, while some just expect a name.

Re: Passing only folder name in embedded scripts

PostPosted: Mon Mar 29, 2021 2:40 pm
by MikeBowden
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.

Re: Passing only folder name in embedded scripts

PostPosted: Tue Mar 30, 2021 9:36 am
by Mr_Noodle
This is more of a general shell scripting issue, but look into the 'basename' command.