Within FileMaker Pro I do have a “Perform AppleScript” function executing the following command (i.e. triggering the application CopytoUSB).
Perform AppleScript
tell me
activate
set s to display dialog "Which appliation do you want to start?" default answer "CopytoUSB"
do shell script "open -a \"" & text returned of s & "\""
end tell
CopytoUSB
try
tell application "FileMaker Pro Advanced"
set _CompID to cell "CompID" of table "Preferences"
set _cardVolume to USBname
set theRecord to current record of table "Preferences"
tell theRecord
set cell "vgCopytoUSB" to "Yes" of table "Preferences"
end tell
end tell
end try
The purpose of this function is to behave according to the information contained in cells _CompID and _cardVolume. In the meantime the program is to assign a value to the cell “vgCopytoUSB” of the table “Preferences”. At this moment it should be “Yes”.
Getting the values contained in cells _CompID and _cardVolume work like a charm. However, I cannot get the cell “vgCopytoUSB” to be initialise to “Yes”.
Would someone have an idea why I cannot send a value to the field “vgCopytoUSB” ?
I never work with tables like this in FM, but the line:
set cell "vgCopytoUSB" to "Yes" of table "Preferences"
is telling “theRecord”, which is already defined as referencing the table, so using “of table” is redundant (and ’ of table “Preferences” ’ would be placed right after the cell name anyway) .
Using the information you’ve provided I did the following and it does now work. I can update a FileMaker Pro cell directly within an AppleScript function.
I can now move further.
Your help have been greatly appreciated.
try
tell application "FileMaker Pro Advanced"
set _CompID to cell "CompID" of table "Preferences"
set _cardVolume to USBname
set data cell "vgCopyUSB1" of table "Preferences" to "No"
end tell
end try
I am trying to update two fields which are not stored on the same table. The first one is on the Preference table and the second one SDHCcard table.
Storing a value in cell vgCopyUSB1 works fine. Unfortunately, I am getting the error message “Object not found” when trying to set the cell of the table SDHCcard.
Would someone have an idea, why I am getting that error message? Once, I will have resolved this issue I will implementing the functionality to add new record to table SDHCcard.
try
tell application "FileMaker Pro Advanced"
set _CompID to cell "CompID" of table "Preferences"
set _cardVolume to USBname
set data cell "vgCopyUSB1" of table "Preferences" to "No"
set data cell "vgCopingSDHC" of table "SDHCcard" to "Cmpl"
end tell
end try
I also tried with Layout and I am getting the same error message.
set data cell “vgCopingSDHC” of table “SDHCcard” to “Cmpl”
If there is more than one record in table SDHCcard (or the field is not a global) then FM will not necessarily know which record’s cell to set.
Normally you would do something like:
set newRec to create new record at table "x" of database "y"
-- now you can use newRec to refer to the newly created record
set data of cell "z" of newRec to "somedata"
-- try making sure the field is on the current layout
When running the script the first time a new record in the sdhcCARD table gets created and the cells (“_EmptyingSDHC”, “_EjectSDHC”) get updated correctly.
The next time the script is run a new record gets created, however the cells “_EmptyingSDHC”, “_EjectSDHC” of the first record gets updated not the new one. Everything stays blank on the new record (i.e record #2).
If I run it again a third record gets created and the cells “_EmptyingSDHC”, “_EjectSDHC” of the first record gets updated not the new one. Everything stays blank on the new record (i.e record #3).
I’ve tried using something like current record and it did not make any differences. I may had the syntax wrong.
Would someone have an idea why the cells on the new created would not get updated, always the one contained on the first record get updated.
Many thanks!
Daniel
tell application "FileMaker Pro Advanced"
set newSDHCrec to create new record at table "sdhcCARD"
end tell
my setFMP("Completed", "Emptying SDHC", "Emptying SDHC card on computer", newSDHCrec)
my setFMP("Completed", "Eject SDHC", "Ejecting SDHC card from USB port", newSDHCrec)
on setFMP(Status, FMPstep, messageFMP, newSDHCrec)
tell application "FileMaker Pro Advanced"
if FMPstep = "Emptying SDHC" then
set data of cell "_EmptyingSDHC" of table "sdhcCARD" to Status
else if FMPstep = "Eject SDHC" then
set data cell "_EjectSDHC" of table "sdhcCARD" to Status
end if
end tell
end setFMP
I keep trying different ways to solve my problem. I now get the error message “Object or property is the wrong type”.
Unfortunately, I do not have enough experience in both FileMaker Pro and Applescript. I used to perform programming, however the old way i.e Cobol, PL/1.
Thanks for your precious help!
Daniel
tell application "FileMaker Pro Advanced"
set newSDHCrec to create new record at table "sdhcCARD"
end tell
my setFMP("Completed", "Emptying SDHC", "Emptying SDHC card on computer", newSDHCrec)
my setFMP("Completed", "Eject SDHC", "Ejecting SDHC card from USB port", newSDHCrec)
on setFMP(Status, FMPstep, messageFMP, newSDHCrec)
tell application "FileMaker Pro Advanced"
tell table "sdhcCARD"
tell record newSDHCrec
if FMPstep = "Emptying SDHC" then
set data of cell "_EmptyingSDHC" of table "sdhcCARD" to Status
else if FMPstep = "Eject SDHC" then
set data cell "_EjectSDHC" of table "sdhcCARD" to Status
end if
end tell
end tell
end tell
end setFMP
This is why I always go to the record I want to update and use this construction:
tell window x
tell layout x
set data cell x of current record to “x”
end tell
end tell
Whenever you are in one table and refer to a related table, only the first record in the related table is accessible to get and set data. I think this is one of the sources of the error. Try the above method of actually going to the record you want to update. You can freeze the screen and navigate using FM script steps just before the Perform Applescript script step if desired, and then navigate back with an FM script step.