[OFF] utility for files

David Hood david.hood at stonebow.otago.ac.nz
Sun Feb 16 08:51:57 CST 2003


On Saturday, February 15, 2003, at 10:33  PM, Ruslan Zasukhin wrote:

> on 2/15/03 10:48 AM, David Hood at david.hood at stonebow.otago.ac.nz 
> wrote:
>> Applescript.
> Okay, but what about more improvement?
> In my dream I select in Finder, few files, choose in context menu 
> special
> item
>         ChangePrefix
>         AddPrefix
>         ChangeSuffics
>         AddSuffics
> Get dialog with one or two edit field, enter what I want, and press OK.
> Is this possible?

To get applescript access from contextual menus in Finder you need a 
third party tool like Big Cat ( http://ranchero.com/software/bigcat/ ).
This lets you run applescripts and shell scripts from contextual menus. 
(Note: It's beta, check the list of know bugs/conflicts)

Rewriting the change prefix script as a script for Big Cat with dialog 
boxes:

on main(filelist)
	---- Get old prefix and chance to quit
	set oldDialog to display dialog "Old Prefix:" default answer "" 
buttons {"Cancel", "Next"} default button 2
	set buttonCheck to button returned of oldDialog
	set oldPrefix to text returned of oldDialog
	if buttonCheck = "Cancel" then
		return
	end if
	---- Get new prefix and chance to quit
	set newDialog to display dialog "New Prefix:" default answer "" 
buttons {"Cancel", "Change"} default button 2
	set buttonCheck to button returned of newDialog
	set newPrefix to text returned of newDialog
	if buttonCheck = "Cancel" then
		return
	end if
	----loop through selected files
	repeat with oneFile in filelist
		tell application "Finder"
			set currentname to name of oneFile
			
			set oldPrefixLength to length of oldPrefix
			set fileStart to text 1 through oldPrefixLength of currentname
			
			if fileStart = oldPrefix then -- only change if file has old prefix
				set noPrefix to text (oldPrefixLength + 1) through 
(length of currentname) of currentname
				set currentname to newPrefix & noPrefix
			end if
			set name of oneFile to currentname
		end tell		
	end repeat	
end main



More information about the Valentina mailing list