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


Click here to return to the '10.4: Make any folder a burn folder' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Make any folder a burn folder
Authored by: robg on Sep 23, '05 01:26:11PM
Yes, that's exactly what I did. My entire "unmake" action looks like this:
  1. Get Selected Finder Items
  2. Run Shell Script (/bin/bash, pass as arguments):
    Do shell script "mv for f in "$@"
    do
        mv "$f.fpbf" "$f"
    done
    
Step two fails, every time. It even fails with a dummy extension (.robg), so this isn't specific to burn folders. The same command works fine in the Terminal (and the reverse command to add the extension works in Automator), so clearly, even though Automator is saying this is being run as a shell script, the Finder or something is intefering in the process.

-rob.

[ Reply to This | # ]
10.4: Make any folder a burn folder
Authored by: nvdingo on Sep 23, '05 02:04:35PM
I thought i had a working script, but i don't know automator well enough, or even applescript.
This code works when you hit run from the automator workflow editor, but does
NOT work if you make it a finder plugin nor does it run if you make it an
application.

it only runs when i test it from the workflow editor as stated above.
when i run it as a plug in or application, it gives me:

Can't make POSIX path of item 1 of {«class cfol» "flash.fpbf" of 
«class cfol» "lindsay" of «class cfol» "Users" of «class sdsk»
  of application "Finder"} into type string. (-1700)

that may be some little applescript thing that i am missing, a class casting here
or there, but i don't know.
my automator action is set as follows
- Get Selected Finder Items
- Run applescript (containing the below code)

on run {myfolders, parameters}
	-- this is by far the kludgiest code i have ever written
	set myNewPath to ""
	repeat with myfolder in myfolders
	    -- this line will leave a trailing /
		set myPath to (POSIX path of myfolder) as string
		
		(* i was having the worst time just figuring out how to trim the trailing / off
		the path name, that the resulting mess is what finally worked and stopped giving
		me NSAppleScript errors that had no explanation with them.
		there must be an easier way to do this, and please, somebody tell me
		the easiest way to trim a single arbitrary character off the end of a string
		*)
		set myPath to text items of myPath
		repeat with i from 1 to ((count of text items in myPath) - 1)
			set myNewPath to myNewPath & ((text item i of myPath) as string)
		end repeat
		-- that mess just stripped the trailing / off my folder
		
		-- use a shell command to find the path to the folder we are looking at
		set myDir to do shell script "dirname " & myNewPath
		
		-- use another shell command to find the basename of the file that has .fpbf
		-- basename always returns just the file, not the path to the file
		set myCurrentFolder to do shell script "basename " & myNewPath & " .fpbf"
		
		-- build our shell script to rename the file and do it
		do shell script "mv " & myNewPath & " " & myDir & "/" & myCurrentFolder
	end repeat
	return myfolders
end run



PS- i hate manipulating strings in applescript, and we shouldn't be forced to buy
Acme script widgets to get the job done either. As good as ASW are, really,
it should be easier to mess with strings in AS

please read comments in code.


[ Reply to This | # ]
10.4: Make any folder a burn folder
Authored by: nvdingo on Sep 23, '05 02:20:50PM
OK THIS ONE WORKS!!! you have to coerce the heck out of the folders passed from get selected items
everything is identical, except for these 2 extra lines

set myfolder to myfolder as alias
set myfolder to POSIX path of myfolder
immediately after the
repeat with myfolder in myfolders
so here is the complete WORKING AS A PLUGIN for the finder code for the run
applescript piece of your workflow

on run {myfolders}
	
	set myNewPath to ""
	repeat with myfolder in myfolders
		set myfolder to myfolder as alias
		set myfolder to POSIX path of myfolder
		
		set myPath to (POSIX path of myfolder) as string
		set myPath to text items of myPath
		repeat with i from 1 to ((count of text items in myPath) - 1)
			set myNewPath to myNewPath & ((text item i of myPath) as string)
		end repeat
		
		set myDir to do shell script "dirname " & myNewPath
		set myCurrentFolder to do shell script "basename " & myNewPath & " .fpbf"
		
		do shell script "mv " & myNewPath & " " & myDir & "/" & myCurrentFolder
		
	end repeat
	return myfolders
end run
enjoy?!?!

[ Reply to This | # ]
10.4: Make any folder a burn folder
Authored by: jecwobble on Sep 23, '05 02:24:20PM

Could it be becasue "$f" actually contains the ".fpbf" extension in it? Notice Mark Hunt's comments: he uses awk to strip off the fpbf extension.



[ Reply to This | # ]