Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

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

Recommended Posts

Posted

Hey,

I use AppleScript to insert files from specific user folders into our Filemaker solution.

The AppleScript (taken from the calc box of Filemaker) looks like

:( To make it clearer, gFilePathAppleScript was: ... :2009/08 GPS:GPS.pdf The result of my calc was accordingly: ... /2009/08 GPS/GPS.pdf However, what I would have needed was: ... /2009[color:red]%2F08 GPS/GPS.pdf So, my question is, how can I convert AppleScript file paths into Filemaker file paths including slashes? My solution so far is a new calculation:


"set Mac_path to (choose file without invisibles default location alias "Macintosh HD:Users:MJ:Documents:") as Unicode text¶¶set field "gFilePathAppleScript" of current record to Mac_path"





The Filemaker script then converts the path that is in gFilePathAppleScript into a path Filemaker can work with by using this calculation:




Substitute ( Table::gFilePathAppleScript ; ":" ; "/" )




Further script steps then use the result to check if another record already has the same path, and, if not, to insert the chosen file into a record.



So far, everything has worked fine. However, today while trying to insert a file Filemaker crashed again and again. I found out that the reason was a sub-folder that contained a slash („/“)
Substitute ( Table::gFilePathAppleScript ; [ "/" ; "%2F" ] ; [ ":" ; "/" ] )

It looks like it works; but isn’t there another "smoother" way to have all the necessary substitutions done? I'm asking this as I'd like to avoid situations where other special characters might cause unforeseen trouble with file and folder names.

Thank you,

Mike

Posted

Get the posix path.

choose file

POSIX path of result

-- "/Users/bruce/Desktop/wiki-basic.fp7"

Posted

Thanks for your help.

Getting the POSIX paths works; but what I then get is

... /2009[color:red]:(08 GPS/GPS.pdf

This doesn't help when setting the actual container field; as for this, I need [color:red]%2F, not the colon [color:red]:. So, I still would need to do a substitution. Or am I missing something?

Posted

This is kind of a long way around, and personally I would do this is a Perform AppleScript "native" (not calculation), and you might just want to do the Substitution in FileMaker. But this AppleScript would replace the "/" in just the file name; using the standard AppleScript Find/Replace subroutine.

I'm separating the file path into the folder & file name. I'm adding the name of the hard disk back at the end, as it gets stripped off by the POSIX path. (Everyone seems to have their own file path syntax.)

set docs to path to documents folder

set file_alias to (choose file default location docs without invisibles)

tell application "Finder"

set file_name_raw to name of file_alias

set file_folder to container of file_alias as alias

set drive_name to name of startup disk

end tell

set folder_posix to POSIX path of file_folder

set file_name to my FindReplace(file_name_raw, "/", "%2F")

set FM_path to "filemac:/" & drive_name & folder_posix & file_name

on FindReplace(txt, f, r)

set astid to AppleScript's text item delimiters

set AppleScript's text item delimiters to f

set TIs to txt's text items

set AppleScript's text item delimiters to r

set txt2 to TIs as text

set AppleScript's text item delimiters to astid

return txt2

end FindReplace

Posted

Thank you very much for taking the time to write this detailed answer. Very enlightening.

I've tried the AS, and it works all fine. The only thing I need to replace as well is the "/" in the folders' names; so that what gets inserted looks like

… /2009[color:red]%2F08 GPS/test-bike[color:red]%2Fmtb.jpg

(The AppleScript way of writing this would be:

… :2009/08 GPS:test-bike/mtb.jpg

for a file named test-bike mtb in a folder named 2009/08 GPS . Adding

set folder_posix to my FindReplace(folder_posix, ":", "%2F")

solves this.)

personally I would do this is a Perform AppleScript "native" (not calculation)

The reason why I use a calculation is that I want AppleScript to open each user's personal folder (which is based on the users' names). Are there technical problems with a calculation?

Posted (edited)

...but another thing: With "choose file", after chosing a file using the little search box in the upper right corner, Filemaker crashes. Time and again. However, when selecting a file by going there step by step through all the folders, everything is fine. I tried it both with "my" version of the script and Fenton's suggestion. (Mac OS 10.6.1, FM Advanced 10.0v3, AS 2.1)

When I search for a file using the search box and start AppleScript from AppleScript Editor, everything is fine. This seems to be a Filemaker related problem.

Edited by Guest

This topic is 5525 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.