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

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

Recommended Posts

Posted

I have a backup Filemaker script that uses the save a copy as script step to place a copy of the database in a backup folder. I then use the Send apple event script step to run a applescript application that changes the name of the copy to system username and current time and date. This applescript application then deletes any copys older than 60 days in the backup folder. The filemaker script runs fine until I run the filemaker database on another computer. Filemaker says it can't find the applescript application :(

Posted

I wouldn't let an applescript do anything to a working file, instead would I use a series of native Export in fm7 format, and then let an embedded applescript be in charge of the renaming process.

Why? How do you ensure that filemaker isn't in the middle of something with the harddisk involved? What the applescript in fact does is something that have a lot in common with OS level sharing concurrently filemakers own protocols dealings.

--sd

Posted

But Søren, he is using the FileMaker Send Event step after running a Save a Copy As. Are you saying the FileMaker would run the Send Event before the Save a Copy As was finished? Personally I think I would run it as you say, in an embedded AppleScript, probably Perform AppleScript. But it would still need to know the previous step was finished.

Posted (edited)

Are you saying the FileMaker would run the Send Event before the Save a Copy As was finished?

I think I didn't get it right, but yes embedded applescripts is my suggestion, instead of having small (redunant) executables showered all over the network, which can get lost. It's to difficult to maintain ...well you can have it stored in a containerfield wich could be unloaded at each user ...but why, when embedded ones are more obvius a choise.

But your question Fenton, brings up a different issue, when ever dealings with external applications or the OS occures mismatches in timings - how would we know if the saving of a copy isn't in fact a call to the operating system to perform the task on filemakers behalf?? Could we monitor such things with processor utilization graphs??

I think the term here is "handshake" - could anyone enlighten us here?

--sd

Edited by Guest
Posted

Yes, he was talking about initiating the AppleScript from FileMaker, not about an external AppleScript running the whole process (which would have timing issues). What we would hope is that FileMaker does not start a script step until the one before it completes. Otherwise almost everything would break, internal or external.

As to your question, whether FileMaker passes off the file writing to the OS, I don't know. I was hoping you did :(-]

Possibly only FileMaker engineers know. But imagine what would happen to a scenario with Export immediately followed by Import (of result). Which was common since FileMaker 3 (to sort a portal, for those of you new to FileMaker :(-).

Posted

Interesting speculations, thank you! I have a silly question but sometimes I simply can't help myself ... would Save A Copy As be dangerous if it is being served? I'm trying to envision packets being transferred, data being stored in cache and records in the middle of being written.

Specifically, whether using FMS or even peer sharing, couldn't this be a problem if being accessed by more than the local system ... more than one User?

Posted

I may not have been clear about why I was doing things.

I have a database that I created for my wife's therapy practice. She uses it on her laptop and syncs it with a desktop computer. I wanted to have the database make a backup into a backup folder whenever she changes information in the database. This would be a script that works when closing the database.

No problem getting the database to backup using the "save a copy as" script step. The problem here was no way to time stamp the backup so you could have multiple backups in the backup folder without overwriting the last backup. The solution I came up with was a applescript that looks for "Clientdatabase copy.fp7" and renames it with system username (so I would know if the backup was from the laptop or desktop computer) and current date/time. The applescript then deletes files older than 60 days.

Why didn't I use the "Perform Applescript" step? I needed to know where the backup folder was located, so I used the applescript "Path of Me" step. That only worked when I made the Applescript an application that was placed in the backup folder.

You are right that there were timing issues with the "Send Event" filemaker script. I ended up surround the "Send Event" step with "Show Custom Dialog" step that waited for the user to click "OK" before continuing.

I would love to have a simpler way to accomplish all of this if any one has ideas

Posted (edited)

This is not even an applescripted task to perform:

Set Variable [ $where; Value:Let(tt=Get(FilePath);LeftWords ( tt ; WordCount ( tt )-1 )) & "/BU_Archive/" & Int(Get ( CurrentDate )) & ". fp7" ] 

Save a Copy as [ “$where” ] [ copy of current file ] 

...only the trimmings of the folders content seems to be so. The above code saves a copy named with the present days numerical value and extention in a folder next to the current working file. Using the "path to me" logic.

Here could a shell scripted deletion be quite handy, to avoid stuffing the expired file in the wastebasket. This could in fact be triggered by a folder action.

http://www.apple.com/applescript/folderactions/03.html

There's no need to bother the base's native scripts further progression, getting rid of the oldest of 61 files ins't particular difficult to sus the apple scripting off.

--sd

Edited by Guest
Posted

thanks for the help.

One thing about your script is that if the user names the database with more than one word it breaks. I guess I would have to check to see how many words are in the database name

Posted

that if the user names the database with more than one word it breaks

At first did this makes me think of:

http://www.azlyrics.com/lyrics/johnnycash/aboynamedsue.html

But then did I realize what the problem was, it's more correct to truncate where the slash is:

Let(tt=Get(FilePath);Left(tt;Position ( tt ; "/" ; 1 ; PatternCount ( tt ; "/" )-1 )-1))

...when it comes to it is the last -1 daft since I'm adding it in the following anyway.

So I would suggest to solve it the following way:


Set Variable [ $where; Value:Let(tt=Get(FilePath);Left(tt;Position ( tt ; "/" ; 1 ; PatternCount ( tt ; "/" )-1 ))) & "BU_Archive/" & Int(Get ( CurrentDate )) & ". fp7" ] 

Save a Copy as [ “$where” ] [ copy of current file ]

--sd

Posted

yes yes

that works great.

Say any ideas on how to creat the backup folder if it doesn't exist

thanks for all your advise

Posted

Now you're back to AppleScript. It seems you want a relative path, as you were talking about using the "path to me" in an AppleScript app. You can get this with FileMaker now. This is your folder path, unstored calculation:

_cMyFolder_AS =

Substitute ( Get ( FilePath ); [ Get (FileName) & ".fp7"; ""]; [ "file:/"; ""]; [ "/"; ":"] )

Put it on a layout, so AppleScript can see it. Then, in a Perform AppleScript step:

set myFolder to cell "_cMyFolder_AS"

set bakFolder to myFolder & "Backups:"

tell application "Finder"

if not (exists folder bakFolder) then

make folder at myFolder with properties {name:"Backups"}

end if

end tell

Posted

Fenton is steering clear of ESC'ing quotes, because it's likely to be tough to debug, but still is it in my opinion a bit overkill to make a dedicated field and layout for such a simple purpose.

If you have a embedded AS calling a shellscript will the error still be a filemaker traceable one, so the entire task could be done in 3 lines of scriptmaker steps:


Set Error Capture [ On ] 

Perform AppleScript [ Calculated AppleScript: Let(thePath= Substitute ( Get ( FilePath ); [ Get (FileName) & ".fp7"; ""]);  "do shell script "mkdir ~"  & Middle(thePath;1+Position(thePath;"/";1;3);99999) &"BACKUP") & """ ] 

Set Error Capture [ Off ]

...this means that an attempt to make yet another folder with the same name at a certain location, will result in a filemaker error message which could be ignored by enclosing it in a pair of:

Set Error Capture['s

So if the folder already exists, tough ....!

The use of shellscripting reduces the need for "-ing down to two.

--sd

Posted

First off thanks to all of you for being so helpful. This has been great.

I attempted to use the calculated applescript as you suggested. I used a show dialog box with get (lasterror) to see what error code to look for. I just get back a "0" or a "1". Am I doing something wrong?

Posted

That is why I go to extra trouble to create fields. So I can see the darn path before I try and execute it. When you use the calculation method Søren suggested, you need to get it right, as you cannot easily see what went wrong, especially since you don't have FileMaker Pro Advanced and cannot walk thru the script.

Why don't you create a temporary calculation field (unstored, important) with the AppleScript stuff (starting with the Let), just to see what you've got.

Posted

But why do any of this with applescript?

Script variables and file naming have been with us since 8.0. You can directly save the file with desired filename using native Filemaker scripting.

Posted

Bruce - Hence this post!

http://fmforums.com/forum/showpost.php?post/262836/

But here later in the thread is issue instead to produce folders, before stuffing the backups in those. Can you really make folders with variables? This must be a folderaction then, but then do you need to utilize shellscript in stead, if applescript is out of the question??

--sd

Posted

Well, you can do the file moving and folder naming/creation later.

Posted

With or without applescript, compiled automator workflows??? It must be out of the reach of a simple native $variable or... ?

--sd

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