Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How can I use a working AppleScript in FM?

Featured Replies

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

  • Author

I solved the problem:


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

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.