Hide stuff from AppleScript result

Hi!
I’m writing my own application in AppleScript studio (almost done) but I miss one -very needed- piece of script.
I want to hide the extension of the result, so far I’ve got:

<lots of things> set theAlmostResult to result set theAlmostFinalResult to POSIX path of theAlmostResult do shell script "basename " & quoted form of theAlmostFinalResult set SearchName to result
and SearchName’s result is Test.app (not a path, nor a file, just a word)

the shell script “basename…” makes Test.app out of /Location/Of/Test.app

I need the name of the application as a word (not a path) and without .app…

Thanks in advance.

Model: PowerBook G4 1.5 GHz
AppleScript: Latest ?
Browser: Safari 528.16
Operating System: Mac OS X (10.5)

Hi,

I use this handler, the parameter f must be a (HFS)path string


on stripNameExtension(f)
	try
		set {name:Nm, name extension:Ex} to info for f as alias
		if Ex is missing value then return Nm
		return text 1 thru ((count Nm) - (count Ex) - 1) of Nm
	on error
		return ""
	end try
end stripNameExtension

So I’ve made it into this :

[code]set f to “/Folder/Test.app” as string

on stripNameExtension(f)
try
set {name:Nm, name extension:Ex} to info for f as alias
if Ex is missing value then return Nm
return text 1 thru ((count Nm) - (count Ex) - 1) of Nm
on error
return “”
end try
end stripNameExtension
set theResult to result
display dialog “” & theResult[/code]
and I can’t get it working, what am I missing ?

REALLY thanks for the reply

Model: PowerBook G4 1.5 GHz
AppleScript: Latest ?
Browser: Safari 528.16
Operating System: Mac OS X (10.5)

If you end up sticking with basename, it can do the extra trimming for you:

set theAlmostFinalResult to "/some/path/to/Test.app"
set SearchName to do shell script "basename " & quoted form of theAlmostFinalResult & " .app"
SearchName --> "Test"

When you give a second argument to basename it will strip that second argument from the end of the first if and only if the result would normally end with the second argument (basename foo/bar.app .txt → bar.app; basename foo/bar.app .app → bar).

A handler is a subroutine which can be called from everywhere in the code


set thePath to "MacHD:Folder:Test.app" -- HFS path!
set fileName to stripNameExtension(thePath)
display dialog fileName

on stripNameExtension(f)
	try
		set {name:Nm, name extension:Ex} to info for f as alias
		if Ex is missing value then return Nm
		return text 1 thru ((count Nm) - (count Ex) - 1) of Nm
	on error
		return ""
	end try
end stripNameExtension


Ah, thanks, really I mean it, both of them worked :smiley:
Now I’ve got one more question about properties but first I’m going to look into it a bit further and if I can’t get it working I’ll make a new thread…

Couldn’t resist this one-liner (which assumes an HSF path with an extension on the file):


set thePath to "ACB-G5_Leopard:Users:bell:Desktop:35FollowingDirections.puz" -- HFS path!
set fileName to stripNameExtension(thePath)
display dialog fileName

on stripNameExtension(f) -- an HFS path, not an alias
	tell (info for (alias f)) to return name's text 1 thru ((my (offset of ("." & name extension) in name)) - 1)
end stripNameExtension