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

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

Recommended Posts

Posted

That's not much to go on for a complete response. Can you expand on what you're doing?

Posted

If I understand you correctly, you can create a container field, copy the file in then out to where every you like.. then if you are done with the file, delete it in the container... this is an easy script, let me know if this help or if you need help writing it.

Posted

My apologies for not being clear.

What I am attempting to do is script a button in my FMP database that will take the contents of a folder that is specified in the DB and make 2 exact copies of all of those files in 2 other locations. That way at the end of the process there is the original set of files and 2 more sets in 2 other folders.

Is that a little clearer?

Posted

FM's OS manipulation can be augmented with Shell scripts and plugins, like Troi's http://www.troi.com/software/fileplugin.html.

However, multiple copies of files raise a red flag for me? Is this some form of backup?

Posted

That's exactly what it is. I think the way I'm leaning is the shell script method. The only thing I'm having trouble with right now is inserting the filepaths's I have in a global field into the shell script.

I assume I use the applescript step to perform a shell script. Or is there another way.

Funny enough I'm using the troi plugin to create my dialogs for the file paths for the primary file location and the 2 secondary (backup) locations.

Posted

Ok now we have a slighty better understanding, what I would do is:

create a batch file that can recieve a variable %n, which is location of the files to copy.

assuming bat file is called copy.bat.

the bach file might look something like:

xcopy %n *.* c:youdir /switches

then create a script, a send event script, use calculation, calculation would be "copy.bat" &" " & fieldnameofpath

I havn't tried this but seems like it should work,let me know if you need help and I write you a program over the weekend..

Posted

Sorry, not familiar with mac, but applescript should have an equiv. to this..

thanks

Posted

So I think I'm getting closer. I'm using the applescript command to run 2 CP shell commands. But I'm having trouble getting the Filemaker filepaths to work in my Applescript for the shell command. This is what I have so far.

set sourcefolder to cell "File Location" of current record



set dest1 to cell "Backup 1" of current record



set dest2 to cell "Backup 2" of current record



set sourcefoldersh to my ConvertPath(sourcefolder)

set dest1sh to my ConvertPath1(dest1)

set dest2sh to my ConvertPath2(dest2)



on ConvertPath(sourcefolder)

	set AppleScript's text item delimiters to "/"

	set x to sourcefolder's text item

	set AppleScript's text item delimitiers to ":"

	set z to x's text items as text

	return z

end ConvertPath	



on ConvertPath1(dest1)

	set AppleScript's text item delimiters to "/"

	set x to dest1's text item

	set AppleScript's text item delimitiers to ":"

	set z to x's text items as text

	return z

end ConvertPath1



on ConvertPath2(dest2)

	set AppleScript's text item delimiters to "/"

	set x to dest2's text item

	set AppleScript's text item delimitiers to ":"

	set z to x's text items as text

	return z

end ConvertPath2	



do shell script "cp -R " & sourcefoldersh & dest1sh

Posted (edited)

Ah, I'm not sure what's going on here. We need to see what your path field has in FileMaker, to know what needs to be done.

But some of that AppleScript is just wrong; and I don't even know why you're using it. It appears to be designed to convert a Unix path to a Mac path. However:

1. You're then running a Unix command, via do shell script. So you want a safe Unix path.

2. There is a known way to convert paths, in either direction.

Required reading (solves many dilemmas) is this Apple Tech Note on using do shell script.

http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html

To convert a "Mac" AppleScript path to a safe Unix path:

set unix_path to quoted form of POSIX path of (choose file)

-- '/Users/fej/Desktop/File_no_Print.png'

-- the single quotes escape spaces in the path

(*

example input; either an alias to a file (such as choose file), or the Mac text path

alias "Macintosh HD:Users:fej:Desktop:File_no_Print.png"

"Macintosh HD:Users:fej:Desktop:File_no_Print.png"

*)

If you are starting with a FileMaker syntax path, such as you get from Insert into a Container field, then you would likely use FileMaker Text functions to convert it to a Unix path. All these paths are similar, but different in known ways.

P.S. A subroutine does not have to be duplicated in order to use it for different data, as long as the parameters sent are the same (in this case only one). The parameter name(s) in the 1st line of a subroutine is immaterial, can be anything. Same for the return line. They can all be anything (though short and descriptive is nice).

An AppleScript subroutine can be considered to be like a function.

on ConvertPath1 & 2 are redundant. Just one subroutine will do whatever you toss at it. Whatever data you sent to it from the main script will get sent to the subroutine (at that position in the parameters), whatever variable you're setting to the result will get what is returned, no matter the internal names within the subroutine.

Edited by Guest
Posted

Thanks for being so gentle. Newbie here. That Apple Tech article is awesome. Thanks so much for that. I'm going to try it all right now.

I'll post back if I have any more trouble.

  • 1 month later...
Posted

So after a little time off from the project I'm back at it. So I had a script working for Backup now it seems broken saying it can't find an object. I'm copying the contents of a folder to 2 other locations. This is the script I have so far:

PerformAppleScript[set sourcefolder to cell "File Location" of current record

set dest1 to cell "Backup 1" of current record

set dest2 to cell "Backup 2" of current record

do shell script "cp -R " & quoted form of the POSIX path of sourcefolder & " " & quoted form of the POSIX path of dest1

do shell script "cp -R " & quoted form of the POSIX path of sourcefolder & " " & quoted form of the POSIX path of dest2

]

File location and the 2 backup locations are filemaker paths. But like I said when I run it I get an "Object not found Error" and then Unknown Error: -1728

To create the global fields I'm using Troi File Plugin to give a dialog box for the Locations.

Thoughts?

Posted

So after a little more work I think I need to re-think this whole thing. What I'm attempting to do is create a backup of a file that I'm adding to the database so I can track it. I have a photo and I want to copy it to one central storage location and then on to 2 other locations so basically 3 copies of the photo. So I'm thinking a container file with a script to move it to a central location then a copy script like the one above to copy it to the 2 backups?

Thoughts?

Posted (edited)

File location and the 2 backup locations are filemaker paths.

But Mac paths (which AppleScript uses) and Unix paths (which do shell script uses) are NOT FileMaker syntax paths. So I can't see how any of this would work.

It is fairly easy to coerce one syntax to the other. But you have to coerce the FileMaker syntax path to either Unix or Mac to start with. It kind of depends which you're going to use; but, as you saw, AppleScript has built-in commands to go to Unix and back. But AppleScript cannot deal with a FileMaker syntax path directly.

AppleScript coercions:

quoted form of POSIX path of "Mac path" -- Mac to Unix

POSIX file "Unix path" -- Unix to Mac (happens instantly when you compile)

P.S. FileMaker syntax to AppleScript Mac path (taking path from Container field, image or file stored as reference only; most common use).

Let ( [

info = GetAsText ( Contain );

vc = ValueCount ( info );

FM_path = GetValue( info; vc )

];

Substitute ( FM_path; ["imagemac:/"; ""]; ["filemac:/"; ""]; ["/"; ":"] )

)

Edited by Guest
Posted (edited)

Thanks for all your help on these stupid issues that a newbie is having. I will give that a try to add it to my script and see what happens.

Just so I'm clear that syntax should be added to my Applescript? Or am I totally confused?

Edited by Guest

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