Jump to content

How can I use a working AppleScript in FM?


This topic is 6914 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I have created an AppleScript which works fine when I run from my AppleScript Editor. But when I copy it into FM and after I escaped all quotes I can't get it to run. It runs fine in FM as native script, but when I try to use it as Calculated AppleScript I get errors. confused.gif

Here is my script:

property theFMPath : "file:/Mac hd/Users/X/Documents/foo/bar/baz/quux v1M 0.9.fp7"

property theFMFile : "quux v1M 0.9.fp7"



property theFolder : "export " & theFMFile

property theAlias : "export"



tell application "Finder"

	--Convert path from FM format (file:/foo/bar/baz/quux.fp7) to AS format (foo/bar/baz)

	log "theFMPath = " & theFMPath

	set savedTextItemDelimiters to AppleScript's text item delimiters

	try

		set AppleScript's text item delimiters to {"/"}

		set theCount to (number of text items in theFMPath)

		log "theCount = " & theCount

		set theTmpPath to text items 2 thru (theCount - 1) of theFMPath

		log "theTmpPath = " & theTmpPath

		set thePath to ""

		set theDelimiter to ""

		repeat with currentFile in theTmpPath

			log currentFile

			set thePath to thePath & theDelimiter & currentFile

			set theDelimiter to ":"

		end repeat

		log "thePath = " & thePath

		set AppleScript's text item delimiters to savedTextItemDelimiters

	on error

		set AppleScript's text item delimiters to savedTextItemDelimiters

	end try

	--Create DB specific export folder 'export-<DB name>'

	if (exists folder theFolder of folder thePath) then

		delete folder theFolder of folder thePath

	end if

	make new folder at folder thePath with properties {name:theFolder}

	--Create generic alias 'export' pointing to 'export-<DB name>'

	if (exists file theAlias of folder thePath) then

		delete file theAlias of folder thePath

	end if

	make alias file to (folder theFolder in folder thePath) at folder thePath with properties {name:theAlias}

end tell
 



What I'm trying to do is use FM functions Get(FilePath) and Get(FileName) to populate the properties theFMPath and the FMName.



I have reduced my script to this snippet in the Calculated AppleScript part:

 
"

property theFMPath : "file:/Mac hd/Users/X/Documents/foo/bar/baz/quux v1M 0.9.fp7"

property theFMFile : "quux v1M 0.9.fp7"

" 




and FM keeps saying:

 
A "property" can't go after this """.
If I use only one property, it works: confused.gifconfused.gifconfused.gif I also tried to make the path conversion more elegant, but I always got errors when running it from my AppleScript Editor:

(*theFMPath = file:/Mac hd/Users/X/Documents/foo/bar/baz/quux v1M 0.9.fp7*)

tell application "Finder"

get POSIX file "file:/Mac hd/Users/X/Documents/foo/bar/baz/quux v1M 0.9.fp7"

"Finder got an error: Can't get POSIX file "file:/Mac hd/Users/X/Documents/foo/bar/baz/quux v1M 0.9.fp7"."

BTW, I tried it with and without the combinations of leading "file:", "/", and "Mac hd".

Any suggestions would be highly welcome.

Cheers

Michael

"

property theFMPath : "file:/Mac hd/Users/X/Documents/foo/bar/baz/quux v1M 0.9.fp7"

" 




 
	log "theFMPath = " & theFMPath

	set theMacPath to POSIX file theFMPath

	log "theMacPath = " & theMacPath

Link to comment
Share on other sites

This topic is 6914 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.