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


Click here to return to the 'Easily create HFS-aware PKZIP and unix archives' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Easily create HFS-aware PKZIP and unix archives
Authored by: ChiperSoft on Nov 26, '03 06:24:48PM
I put this to work in AppleScript to create a droplet for making macbinary zip files that stuffit can handle. Here's the applescript:

-- This droplet is based upon the droplet examples on Apple's AppleScript site.
on open these_items
	repeat with i from 1 to the count of these_items
		set this_item to item i of these_items
		set the item_info to info for this_item
		if (alias of the item_info is false) then
			process_item(this_item)
		end if
	end repeat
end open

-- this sub-routine processes folders 
on process_item(this_item)
	
	set file_path to POSIX path of this_item
	set file_path to trim_lineend(file_path, "/") --this is needed so that ditto can properly handle directories
	
	set the_command to "ditto -c -k -X --rsrc " & quoted form of file_path & " " & quoted form of (file_path & ".zip")
	
	do shell script the_command
end process_item

on trim_lineend(this_text, trim_chars) --modified from a subroutines on the AppleScript site
	set x to the length of the trim_chars
	repeat while this_text ends with the trim_chars
		try
			set this_text to characters 1 thru -(x + 1) of this_text as string
		on error
			-- the text contains nothing but the trim characters
			return ""
		end try
	end repeat
	return this_text
end trim_lineend
Save the script as an application. the zip file will be created in the same directory as the dropped file/folder

[ Reply to This | # ]
Easily create HFS-aware PKZIP and unix archives
Authored by: SOX on Nov 26, '03 11:06:55PM

thanks!
I've been trying to figure out how to do charater editing and regular expressions in applescript to delete that last slash. Is there a good online ref that teaches apple script? I find either super fcicila things, examples or hideous-to-read reference manuals that make no sense to me.

three things I'm trying to figure out is how to extract the filename from some fully qualified path (that might incude spaces). How to extract the enclosing folder name, again without the path. and how to extract the filename without the suffix or path. (e.g. so I can write something like
[code]
command /path/myarch.bzip2 /newpath/myarch.cpio
[\code]
when given the name /path/myarch.bzip2 I need to be able to create the name /newpath/myarch.cpio
I can do this by calling perl and using regular expressions but there must be some way to do it in applscript directly. plus it gets ugly in perl when there are special chearacters in the file name that need meta-quoting.

any suggestions?



[ Reply to This | # ]