Jump to content
The ORIGINAL FileMaker Community - Forum - Online Business Apps & Software Forum

Recommended Posts

Hyperscripter

OK, I have a script named 'A Records' written entirely with AppleScript and it works perfectly fine.It brings up a 'choose from list' for all records beginning with the letter a. I have one like this for A-z, ie 26 different scripts. The problem that you'll see below, is that I would like to be able to write a single script to cover all of them by knowing the letter associated with the name of the button. I have 26 buttons with names a-z. In bold I have the only script line which differs in all 26 scripts. As I said, the script(s) work fine, I just have the one issue to handle in order to be able to consolidate all 26 scripts into 1. Here is the script

 

try

set restoreDelimiters to AppleScript's text item delimiters

sort layout "Main" by field "Name" in order ascending

set targetAlpha to "A"

set alphaArray to {}

set alphaArray to (ID of every record whose cell "Alpha Descriptor" contains targetAlpha)

sort layout "Main" by field "Name" in order ascending

set convertArray to alphaArray

set AppleScript's text item delimiters to return

set arrayCount to count items in convertArray

set convertedArray to {}

repeat with x from 1 to arrayCount

set convertedID to (item x of convertArray as integer)

set convertedArray to convertedArray & convertedID

end repeat

 

set convertedArrayText to {}

repeat with x from 1 to arrayCount

set convertedName to (get cell "Name" of record ID (item x of convertedArray))

if (text 1 of convertedName = targetAlpha) then set convertedArrayText to convertedArrayText & convertedName

end repeat

 

set arrayCount to count text items in convertedArrayText

set arrayCount to arrayCount as text

set defaultRecord to (text item 1 of convertedArrayText)

set convertedArrayText to arraySort(convertedArrayText)

set targetRecord to (choose from list convertedArrayText with prompt arrayCount & " search results found for '" & targetAlpha & "':" with title "Search: " & targetAlpha OK button name "View" default items defaultRecord)

if targetRecord=false then error number -128

show every record whose cell "Name" = targetrecord

set AppleScript's text item delimiters to restoreDelimiters

on error theError

if theError contains "User canceled" then

return

else if theError contains "not found" or theError contains "empty" then

display dialog "No items found for: '" & targetAlpha & "' !" with title "No Results" with icon 0 buttons "Done" default button 1 giving up after 5

return

else if targetRecord=false then

return

else if theError contains "Object" and targetRecord≠false then

display dialog "No items found for: '" & targetAlpha & "' !" with icon 0 buttons "Done" default button 1 giving up after 5

else

display dialog theError with icon 0 buttons "OK" default button 1

end if

end try

 

on arraySort(theList)

set indexList to {}

set sortedList to {}

repeat (number of items in theList) times

set lowItem to ""

repeat with i from 1 to (number of items in theList)

if i is not in indexList then

set thisItem to item i of theList as text

if lowItem is "" then

set lowItem to thisItem

set lowItemIndex to i

else if thisItem comes before lowItem then

set lowItem to thisItem

set lowItemIndex to i

end if

end if

end repeat

set end of sortedList to lowItem

set end of indexList to lowItemIndex

end repeat

return sortedList

end arraySort

Edited by Hyperscripter
Formatting

Share this post


Link to post
Share on other sites
doughemi

Are you calling the Applescript with an FM script that includes a Perform Applescript command?

 

If so, create a global field ButtonClicked. Create a script CallAS:

 

Set Field[YourTable::ButtonClicked; Get(ScriptParameter)]
Commit Records/Requests
Perform Script["YourScript"]

Modify your Applescript to pull targetAlpha from ButtonClicked instead of entering the literal.

 

In the Perform Script dialog under Button Setup, enter the correct letter in the Script Parameter field and select CallAS as the script to perform.

Edited by doughemi
Added Commit Records to script

Share this post


Link to post
Share on other sites
This thread is quite old. Please start a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.




×
×
  • Create New...

Important Information

Terms of Use