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

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

Recommended Posts

Posted

Relatively new to FileMaker Pro and using version 10. I have googled the topic and spent many hours researching solutions and tried 3 different approaches, all with erroneous results. The database manages employee records. I want to create a script that automatically creates a folder, named by the fields CREW::FirstName & " " & CREW::LastName and located in Documents/Personnel/Crew/Current, after completing the last name field of a new record (i.e. activated via script trigger on this field) and I do not want it to replace a folder of the same name.

Latest attempt:

Calculated Applescript step -

"do shell script \"mkdir /Macintosh HD:Users/Dan/Documents/Personnel/Crew/Current/" & CREW::PersonalDetailsFolderName & " 2> /dev/null\""

Previous attempt:

Native Applescript step -

--tell application "FileMaker Pro Advanced"

set FolderName to cell "PersonalDetailsFolderName" of current record

--end tell

set FolderPath to path to "Macintosh HD:Users/Dan/Documents/Personnel/Crew/Current"

tell application "Finder"

try

make new folder at FolderPath with properties {name:FolderName}

end try

end tell

First attempt:

Script steps -

Set Variable [$NewFolder ; CREW::FirstName & " " & CREW::LastName & "/"]

Perform Applescript [Let ( Qmk = "'" ; " do shell script " & Qmk & "mkdir /MacintoshHD/Users/captainmyladymarina/Documents/Personnel/Crew/Current/" & CREW::PersonalDetailsFolderName & Qmk )] - Calculated Applescript

All result in errors. I'm sure all approaches are syntax errors. I wish I could find a good reference for script syntax; however, I would gladly accept an explicitly written code suggestion. Please help.

Posted

I think you are mixing two forms of path syntax: within AppleScript, the folder path should be specified as:

"Macintosh HD:Users:Dan:Documents:Personnel:Crew:Current"


 

Within a shell script, it should be:

 


"/Users/Dan/Documents/Personnel/Crew/Current"

Posted

Hello "Consultant",

Thank you for your reply. Based on your syntax error observation, the only attempt this applies to is the Previous where I used Native Applescript. Therefore, I changed this script accordingly to:

--tell application "FileMaker Pro Advanced"

set FolderName to cell "PersonalDetailsFolderName" of current record

--end tell

set FolderPath to path to "Macintosh HD:Users:captainmyladymarina:Documents:Personnel:Crew:Current"

tell application "Finder"

try

make new folder at FolderPath with properties {name:FolderName}

end try

end tell

Result returned same error message - "Object not found". Then after clicking "OK" - "Unknown Error: -1728."

Please help.

Posted

Hello again "Consultant",

My bad; I noticed I must also change the latest shell script attempt as follows:

"do shell script \"mkdir /Macintosh HD/Users/Dan/Documents/Personnel/Crew/Current/" & CREW::PersonalDetailsFolderName & " 2> /dev/null\""

The error message is still the same with this as well - "The command exited with a non-zero status."

Please help.

Posted

Your path is still incorrect. Also, if you want the directory to be created automatically, you need to use mkdir -p, I think. I am not sure what the > /dev/null part is for.

BTW, you can generate the first part of the path dynamically with:

set myPath to POSIX path of (path to documents folder) & "Personnel/Crew/Current/"

Posted

Hello again "Consultant",

Can you please tell me specifically what is wrong with the path as written in my last post; I don't see the incorrectness to which you refer? As I understand it, mkdir -p will overwrite any existing folder, which I do not want to do; I only want to create the folder if it does not already exist. FYI, this approach was learned from the following forum:

http://hintsforums.macworld.com/archive/index.php/t-85125.html

Also, I assume your last dynamic path suggestion applies as follows?

--tell application "FileMaker Pro Advanced"

set FolderName to cell "PersonalDetailsFolderName" of current record

--end tell

set FolderPath to POSIX path of (path to documents folder) & "Personnel/Crew/Current/"

tell application "Finder"

try

make new folder at FolderPath with properties {name:FolderName}

end try

end tell

FYI, this approach was learned from the following forum link:

http://fmforums.com/forum/topic/58887-creating-a-folder-alias-with-applescript/

Thanks again!

Posted

Can you please tell me specifically what is wrong with the path as written in my last post

You have:

/Macintosh HD/Users/Dan/Documents/Personnel/Crew/Current/

You should have:

/Users/Dan/Documents/Personnel/Crew/Current/

As I understand it, mkdir -p will overwrite any existing folder, which I do not want to do

-p Create intermediate directories as required. If this option is not specified, the full path prefix of each operand must already exist. On the other hand, with this option specified, no error will be reported if a directory given as an operand already exists.

http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/mkdir.1.html

See also:

http://macscripter.net/viewtopic.php?id=16156

I assume your last dynamic path suggestion applies as follows?

No, I was still referring to the shell script. You cannot use a POSIX path with Finder.

Posted

Hello again "Consultant",

OK, all is clear with mkdir -p and your recommendations regarding POSIX; however, I still seem to have an issue that I need to use a field name as the dynamic part of the folder, so I assume this must be a calculated Applescript. I assume all lines of this suggested Applescript approach should be 1 line of a FileMaker script; i.e. Perform Applescript? The calculated Applescript does not handle double quotes, which it appears that I need (it closes the quote rather than quote within a quote). Separate Applescript lines of command in the FileMaker script don't work; the next line does not recognize a variable established in a previous Applescript line. Here again, I'm lost in the syntax. Sorry for all the hand-holding, but I'm new to this; all suggestion thus far make sense by themselves but I am lost in the assembly. If you could suggest exactly each FileMaker Applescript step of your recommendation, I might be able to glean the approach pattern for this and future uses. Thank you.

Posted

I need to use a field name as the dynamic part of the folder, so I assume this must be a calculated Applescript.

No, it doesn't - you can use native AppleScript to get data from Filemaker, like you did in your first attempt:

--tell application "FileMaker Pro Advanced"

set FolderName to cell "PersonalDetailsFolderName" of current record

--end tell


 

 

I assume all lines of this suggested Applescript approach should be 1 line of a FileMaker script; i.e. Perform Applescript?
Yes.
The calculated Applescript does not handle double quotes, which it appears that I need
A calculated AppleScript must return the text of a valid AppleScript. AppleScript itself does not accept nested quotes of the same type - but it does accept single-quoted expression within a double-quoted one, e.g.

If you could suggest exactly each FileMaker Applescript step of your recommendation, I might be able to glean the approach pattern for this and future uses.

Hopefully you should be able to put it together now. I could write it out for you, but where is the fun in that?

do shell script "mkdir -p '/Users/Dan/Documents/Personnel/Crew/Current/'"


 

But you don't need to worry about quotes if you pre-define some variables as text. For example:

 


set myPath to POSIX path of (path to documents folder) & "Personnel/Crew/Current/"

set myCommand to "mkdir -p " & quoted form of myPath


 

At this point, the variable myCommand contains the string:

 

"mkdir -p '/Users/Dan/Documents/Personnel/Crew/Current/'"

 

and all you need to do is add:

 


do shell script myCommand
Posted

OK, I should've seen Applescript retrieval of the FM Pro cell myself. However, my Applescript is still returning error messages: "Object not found" and then when OK is clicked, "Unknown error :-1728." Exact script is:

--tell application "FileMaker Pro Advanced"

set FolderName to cell "PersonalDetailsFolderName" of current record

--end tell

set FolderPath to POSIX path of (path to documents folder) & "Personnel/Crew/Current/"

set mkdirStr to "mkdir -p " & quoted form of FolderPath & quoted form of FolderName

do shell script mkdirStr

What am I missing...?

Posted

Try this in AppleScript Editor (while your Fiiemaker solution is open):

tell application "FileMaker Pro Advanced"

set FolderName to cell "PersonalDetailsFolderName" of current record

end tell

 

set FolderPath to POSIX path of (path to documents folder) & "Personnel/Crew/Current/"

 

set mkdirStr to "mkdir -p " & quoted form of FolderPath & quoted form of FolderName

What do you see in the Result tab?

Posted

OK, found

http://help.filemaker.com/app/answers/detail/a_id/4285/kw/protect%20fields%20from%20modification/session/L3RpbWUvMTMxMTM2MTg2Ni9zaWQvQzdCamNFems%3D

and realized error resulted from field not on the layout. Put the field on the layout and ran again in Applescript Editor (because it is not performing in FM, but no longer giving error messages:

"mkdir -p '/Users/captainmyladymarina/Documents/Personnel/Crew/Current/'''\\''Daniel Higlett'\\'''"

Seems the forward slashes and quote arrangement is wrong. Any ideas?

Regarding my last, seems like I'm striving for:

"mkdir -p '/Users/captainmyladymarina/Documents/Personnel/Crew/Current/Daniel Higlett'"

But not sure how to get there.

Posted

I was hoping seeing the result would make it clear: you are appending two quoted strings,when they need to be inside the same quote. Try it this way (untested):

--tell application "FileMaker Pro Advanced"

set FolderName to cell "PersonalDetailsFolderName" of current record

--end tell



set myPath to POSIX path of (path to documents folder) & "Personnel/Crew/Current/" & FolderName  & "/"

set myCommand to "mkdir -p " & quoted form of myPath

do shell script myCommand

Posted

Well, that did the trick! Thank you again!!

BTW, I didn't see it because I don't yet see the difference between appending the 2 quoted strings "mkdir -p " & quoted form of myPath and quoted form of FolderPath & quoted form of FolderName. Too new to this I guess but learning...

Posted

I don't yet see the difference

Appending two quoted strings:

quoted form of "a" & quoted form of "b"

returns:

"a""b"

Appending two strings, then quoting the result:

set c to "a" & "b"

quoted form of c

returns:

"ab"

  • 2 years later...
  • Newbies
Posted

hope i can tack on to the end of this thread

 

im trying to do almost the same thing as above but to a NAS drive...

 

any help?

Posted

hope i can tack on to the end of this thread

 

im trying to do almost the same thing as above but to a NAS drive...

 

any help?

 

You'd have to quote what NAS drive you’re using and what version of unix it is running. The above commands apply to Mac OSX, as far as I can tell.

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