Newbie: Use first word of file name as a variable

I’m working on a droplet that reformats a .csv file exported from FileMaker Pro, and saves it to a text file (.xtg) to be imported into Quark XPress. The exported file is saved to the desktop as “Saturday Final.csv”.

I need to get the first word “Saturday” from the file name, and use it in the droplet to generate the name of the new .xtg file. “Saturday Final.xtg”

The droplet will also use the name to delete the old .csv file when it’s done with the formatting and has saved the new .xtg file.

set theDeleteMeFile to (path to desktop as Unicode text) & theDay & " Final.csv"
Tell application "Finder" to move theDeleteMeFile to the trash
end tell

Thanks in advance for the help. Also if anyone could point me toward a comprehensive source that explains why FileMaker Pro 9 is so picky about Applescript it would be great. I would rather have FileMaker run the “native” AS to format this text, but I’m too inexperienced with Applescript to continue to fight with FileMaker - hence the droplet.

OK, so I figured out a way to get what I needed. I’m sure there is a better way, but for newbies it’s about the destination, not so much the journey …

	set OldDelims to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {":"}
	set theDate to text item -1 of theExportedFile
	set AppleScript's text item delimiters to {" "}
	set theName to text item 1 of theDate
	set AppleScript's text item delimiters to OldDelims

In AppleScript you can ask for the first word of a string:

set theWord to first word of theString

To get the first word of a file name:

set theFile to choose file
set theDay to first word of (name of (info for theFile))

I think this is the quickest way.


Thanks! :slight_smile: