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

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

Recommended Posts

Posted

I have a script (droplet) that gets the file names of files inside a folder (that is dropped on it). The script first gets some info from the files, and sends one part to FMP to insert into a field. Then from a portal that matches the data, another regular field is filled in via a script in FMP. This sets up where the actual data about individual files will go. The script is set to "transcation" so that part will run. The names of the files are put into some generic text container fields (from the script). Then lastly, the script tells a FMP script to create each file in a portal.

This script works great on the computer it's running on, the FMP server. When I try the script on a different Mac (running it from that Mac's HD), it will only get through one or two steps and not put in the file name info or create the data in the portal (last step).

Is FMP really picky about transactions or timing? I tried to add a delay of 1 between steps, but that did not help. Is there trouble with portals or lookups that get in the way of scripts?

The script gets some info from the comments part of the folder. It asks to fill some in. It strips out the text part of the file names, and gets only the file numbers (page numbers). Then the page numbers are "p1", "p2", etc. Here's the script:

on run

display dialog "Drop a set folder on this script to add it to the eTracker. You must enter the Book Run number first when you are asked." with icon 1

end run

on open ThisFolder

set ThisFolder to ThisFolder as text

tell application "Finder"

set FolderInfo to comment of folder ThisFolder

end tell

try

((characters 1 thru 4 of FolderInfo as text) as number)

on error

display dialog "This folder does not have the correct area information in it. It cannot automatically be added to the GigabyteTracker." with icon 0 buttons "Cancel" default button 1

end try

set MyArea to (characters 1 thru 4 of FolderInfo) as text

set MyYear to (characters 7 thru 8 of FolderInfo) as text

set MySet to (characters 9 thru 10 of FolderInfo) as text

if (characters 5 thru 6 of FolderInfo) as text is not "__" then

display dialog ("This set may have already been added to the GigabyteTracker. Its code is:" & return & return & (characters 1 thru 10 of FolderInfo) as text) & return & return & "Press Cancel unless you are sure you want continue." with icon 0

set BookCode to (characters 1 thru 8 of FolderInfo) as text

set BookCodeSet to (characters 1 thru 10 of FolderInfo) as text

else

display dialog "Please enter the Book Issue number:" & return & return & MyArea & " _ _ " & MyYear & " set " & MySet & return & return default answer "01" with icon 1

set BookCode to (MyArea & text returned of result & MyYear) as text

set BookCodeSet to (BookCode & MySet) as text

end if

display dialog "Confirm Book Code:" & return & return & BookCodeSet & return & return & "(Press cancel to start over.)" with icon 0

tell application "Finder"

set comment of folder ThisFolder to BookCodeSet & return & FolderInfo

set FileCount to count files of folder (ThisFolder as text)

set name2 to characters 1 thru -2 of (ThisFolder as text) as string

set name3 to characters ((-(offset of ":" in (the reverse of every character of name2 as string))) + 1) thru -1 of name2 as string

set name4 to characters 1 thru -9 of name3 as string

set NameConvCount to count characters of (name4 as text)

if FileCount >= 1 then

set P1 to characters (NameConvCount + 1) thru -5 of (name of item 1 of folder (ThisFolder as text) as string) as text

if (count of characters of P1) = 1 then set P1 to ("0" & P1) as string

else

set P1 to ""

end if

if FileCount >= 2 then

set P2 to characters (NameConvCount + 1) thru -5 of (name of item 2 of folder (ThisFolder as text) as string) as text

if (count of characters of P2) = 1 then set P2 to ("0" & P2) as string

else

set P2 to ""

end if

if FileCount >= 3 then

set P3 to characters (NameConvCount + 1) thru -5 of (name of item 3 of folder (ThisFolder as text) as string) as text

if (count of characters of P3) = 1 then set P3 to ("0" & P3) as string

else

set P3 to ""

end if

if FileCount >= 4 then

set P4 to characters (NameConvCount + 1) thru -5 of (name of item 4 of folder (ThisFolder as text) as string) as text

if (count of characters of P4) = 1 then set P4 to ("0" & P4) as string

else

set P4 to ""

end if

if FileCount >= 5 then

set P5 to characters (NameConvCount + 1) thru -5 of (name of item 5 of folder (ThisFolder as text) as string) as text

if (count of characters of P5) = 1 then set P5 to ("0" & P5) as string

else

set P5 to ""

end if

if FileCount >= 6 then

set P6 to characters (NameConvCount + 1) thru -5 of (name of item 6 of folder (ThisFolder as text) as string) as text

if (count of characters of P6) = 1 then set P6 to ("0" & P6) as string

else

set P6 to ""

end if

if FileCount >= 7 then

set P7 to characters (NameConvCount + 1) thru -5 of (name of item 7 of folder (ThisFolder as text) as string) as text

if (count of characters of P7) = 1 then set P7 to ("0" & P7) as string

else

set P7 to ""

end if

if FileCount >= 8 then

set P8 to characters (NameConvCount + 1) thru -5 of (name of item 8 of folder (ThisFolder as text) as string) as text

if (count of characters of P8) = 1 then set P8 to ("0" & P8) as string

else

set P8 to ""

end if

if FileCount >= 9 then

set P9 to characters (NameConvCount + 1) thru -5 of (name of item 9 of folder (ThisFolder as text) as string) as text

if (count of characters of P9) = 1 then set P9 to ("0" & P9) as string

else

set P9 to ""

end if

if FileCount >= 10 then

set P10 to characters (NameConvCount + 1) thru -5 of (name of item 10 of folder (ThisFolder as text) as string) as text

if (count of characters of P10) = 1 then set P10 to ("0" & P10) as string

else

set P10 to ""

end if

if FileCount > 10 then display dialog "There are more than 10 pages in this set, or there is an error." & return & return & "This set will NOT be added to the database. Please continue manually." with icon 0 buttons "Cancel" default button 1

end tell

tell application "FileMaker Pro"

go to layout "SendingSetupStorage" of database "GigabyteTracker"

set cell "Find_bookcode" to BookCode

delay 1

with transaction

do script "Insert_correct_year_week_forCovers"

end transaction --must remove transaction to compile

delay 1

set cell "newsetwbooknumber" of database "GigabyteTracker" to MyArea

set cell "NewSetBookCodeSet" to BookCodeSet

set cell "NewSetNumber" to MySet

set cell "NewSetNumPages" to FileCount

set cell "p1" to P1

set cell "p2" to P2

set cell "p3" to P3

set cell "p4" to P4

set cell "p5" to P5

set cell "p6" to P6

set cell "p7" to P7

set cell "p8" to P8

set cell "p9" to P9

set cell "p10" to P10

delay 1

do script "MakeNewSet_and_Pages"

end tell

end open

Thanks for the help!

Posted

The main difference between your script run on the host machine and on a guest is access to the folder and files involved. In all your detail you don't mention where the file and folders are. If they are on the host machine and the volume is not shared, you won't be able to get to the files and folders. If they are on the host machine and are shared, the path will be different on the host and guest machines. Remember that the script runs from the perspective (the file paths) of the guests.

-bd

Posted

Thanks!

But the answer really was something more obtuse and not really related to the file's hosted status (I guess).

In the last part, where I have FMP putting values into cells, that is where the script would choke. Apparently, FMP needs a line saying "go to cell...so&so", and then I can do "set cell so&so to BookCode". After I do that then all the other data fills in OK after that. I guess it just needs coaxing to open up the first cell to put values into. tongue.gif

(actually all of our files to "add" to FMP are on our servers, and no single station is "file shared", but thanks for the time to answer!!)

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