double-click a file ...

Hi all

Is it possible, to double-click a file to get it’s file name into an applescript? Any tip or hint would be useful.

Thanx
Lazy

I don’t know exactly what you’re after, but .

This is how you open files in a specified application:

set myApp to choose application
try
	set appHSF to (path to (myApp as application))
on error
	display dialog ("Failed to receive path of application \"" & (name of myApp) & "\"") as string buttons "OK" default button 1
	return
end try

set appPOSIX to quoted form of (POSIX path of appHSF)
set fileToOpen to POSIX path of (choose file with prompt "Choose a file to open.")
do shell script "open " & quoted form of fileToOpen & " -a " & appPOSIX

This is how you retrieve or edit the name of a folder or a file:

set myFile to (choose file with prompt "Choose the file that you want to rename.")

-- GET NAME USING INFO FOR
set originalFileName to name of (info for myFile)

-- GET NEW NAME FROM USER
set newName to text returned of (display dialog ("Give a new name for the file named \"" & originalFileName & "\"") as string default answer originalFileName)

-- NEW FILE NAME 
-- with Finder

(* tell application "Finder" to set name of myFile to newName *)

-- I always try to avoid the use of applications so I do it .
-- . with a shell script
set orPOSIX to POSIX path of myFile
set dir to stringByDeletingLastPathComponent(orPOSIX)
set newPOSIX to stringByAppendingPathComponent(dir, newName)

do shell script "mv " & quoted form of orPOSIX & " " & quoted form of newPOSIX


(* ===== HANDLERS ===== *)
on stringByDeletingLastPathComponent(filename)
	-- if slash
	if filename is "/" then return filename
	
	-- if ends with slash
	if filename ends with "/" then set filename to (characters 1 thru -2 of filename) as string
	set tid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "/"
	set allComponents to every text item of filename
	set AppleScript's text item delimiters to ""
	
	-- if no dir
	if (count allComponents) is 1 then return ""
	
	set allComponents to (items 1 thru -2) of allComponents
	
	set AppleScript's text item delimiters to "/"
	set newPath to allComponents as text
	set AppleScript's text item delimiters to ""
	if newPath does not end with "/" then set newPath to (newPath & "/") as string
	
	set AppleScript's text item delimiters to tid
	
	return newPath
end stringByDeletingLastPathComponent

on stringByAppendingPathComponent(original, addition)
	if original is not "" then if original does not end with "/" then set original to (original & "/") as string
	set newString to (original & addition) as string
	return newString
end stringByAppendingPathComponent

If you really want to click something with a mouse, than I guess you should start looking for an OSAX. I never have used an OSAX, thus I can’t help you on that one.

Hope it helps,
ief2