Can you email me a cut down example?
Itās actually a fairly small script. Just drop it in a folder with other scripts and when you run it (from SD or a script menu) it creates a script palette from the scripts in the folder. You should be able to resize it and put it anywhere you like on the screen. But, after a few runs it forgets its position.
Maybe it happened in editing, but that version has no way of getting out of the repeat loop youāre showing the table in. That means when someone cancels, the script is still running, and is likely to cause all sorts of mischief.
Wait, what? Doesnāt the Cancel button (āClose Paletteā) stop it?
It doesnāt keep running in SD Debugging and the spinning gear stops in the menu.
Sorry, youāre right. It turns out the script runner was still trying to run a Mail action script I was testing yesterday, and that somehow made the error -128 fail to stop the script.
Now that Iāve eliminated that, Iām not seeing the problem you describe. However, there is an issue when itās run on a second screen. Iāll look into it when I get a chance.
Iām just starting a script that will allow the users to generate a table with information about soccer tournaments.
The thing is that each row of the table covers a different aspect of the game and each column a different age group.
Ideally what Iād like to have is a popup menu or combo box in each cell, but with different default values. For example in the row for half-duration, the U-19 options would only be 45, 40, 35, 30. In U-10 the only options would by 25, 20.
Is it possible? It seems the default values are set in the template and apply to the column.
Or maybe I should switch rows/columns?
This script will show what the table would look like with plain text
use script "Myriad Tables Lib" version "1.0.7"
use scripting additions
property tablePosition : {1.0, 24.0, 572.0, 250.0}
property aysoDefaults : {{"Ball size", "4", "4", "5", "5", "5"}, Ā¬
{"Half Duration", "25", "30", "35", "40", "45"}, Ā¬
{"Quarters/Breaks", "12.5", "15", "17:30", "10", "11:15"}, Ā¬
{"Team Size/Min", "7/5", "9/6", "11/7", "11/7", "11/7"}}
property lastSpecs : {}
if lastSpecs is {} then set lastSpecs to aysoDefaults
DisplayCompetitionSpecs(lastSpecs)
on DisplayCompetitionSpecs(tableData)
set columnHeadings to {"AGE/DIV", "U10", "U12", "U14", "U16", "U19"}
set tablePrompt to "Edit Competition Rules"
set multipleSelectionsAllowed to true
set canAddAndDelete to false
set editableColumns to false
set rowNumbering to false
set initiallySelectedRows to {}
set emptySelectionAllowed to true
set tableTitle to "Rules for compeition"
set tableData to make new table with data tableData Ā¬
with title tableTitle Ā¬
with prompt tablePrompt Ā¬
multiple selections allowed multipleSelectionsAllowed Ā¬
can add and delete canAddAndDelete Ā¬
column headings columnHeadings Ā¬
row numbering rowNumbering Ā¬
initially selected rows initiallySelectedRows Ā¬
empty selection allowed emptySelectionAllowed
set OKButtonName to "Confirmed"
set cancelButtonName to "Cancel"
set extraButtonName to "Reset to AYSO defaults"
modify table tableData Ā¬
OK button name OKButtonName Ā¬
OK button is default true Ā¬
cancel button name cancelButtonName Ā¬
extra button name extraButtonName Ā¬
alternate backgrounds true Ā¬
row dragging false Ā¬
without column reordering
set tableResult to display table tableData Ā¬
with extended results
set tablePosition to final position of tableResult
return {values returned of tableResult, button number of tableResult}
end DisplayCompetitionSpecs
Thatās right ā you canāt have different defaults in different places.
Itās working by reversing rows and columns, but all the paperwork and forms that people are familiar with have the age groups across the top and the categories in rows.
Theyāll just have to get used to it.
In a related question have you considered adding a ārow labelsā feature similar to the column headings? That would make managing the tables a bit simpler.
Iāve thought about it, but (a) itās complicated, and (b) keeping it backwards compatible is even more complicated.
Iāll be doing a minor rev shortly, mainly to cope better with Dark Mode in Mojave. Simple requests are welcome, but nothing complex is likely to happen.
I keep getting errors when running in Debugging mode but it does fine in normal mode or when run from Script Editor. Is that fixable?
AppleScript Execution Error
Couldnāt write data because C and Objective-C pointers cannot be saved in scripts.
Ā«data optr00000000A08C7C0040600000Ā»
Iām afraid not. The problem is that debugging relies on storing script descriptors, but descriptors containing pointers canāt be stored. And if we kill the pointers, we kill the tables
Well, since you asked:
There is a UI issue where the prompt displayed seems to be truncated in some cases, when there is plenty of room.
Iāve also got a few scripts where it would be really handy to have a single text entry field at the bottom of the table and a fourth button.
In those cases I have to display a second UI dialog to get the info I need.
Iāve had a couple scripts where it would have been nice to have a popup menu or a combo box for one of the dialog buttons. In those cases the user would pick a date from a list usually. Instead I have to display Choose from List.
From the moment you released Myriad Tables I started incorporating it into numerous scripts. This has become my go-to tool and it improved the interface on numerous older scripts and actually made some operations that would have been nearly impossible simple.
Just for grins I did an Open Quickly search for Myriad Tables and got over 200 hits
Itās a bit of code, but thatās what the accessory view
parameter is designed for. Have you had a play with Accessory View sample.scptd
?
There still seem to be some autolayout glitches, alas. But if you have a reproducable sample, it would be helpful.
Hereās the one where I need it the most. The idea is that you enter information that will populate the IPTC fields for info of every image open tabs in the first window. Say Iām working on a story about āThe Big Bang Theoryā Iād download four or five images from the provider, open them all in Photoshop and run this script. I enter in the fields and combo boxes.
If I hit refresh it is supposed to show me what all the info looks like. Instead it gets truncated.
use AppleScript version "2.4"
use scripting additions
use script "Myriad Tables Lib"
property lastPosition : {50, 50}
property menuTitles : {"", "The Expanse", "Marvels Agents of Shield ", "The Odd Couple", "Love Locks", "Emerald City", "Baskets", "Six", "NCIS New Orleans", "Supergirl", "The Boss"}
property menuChannels : {"CBS", "NBC", "The CW", "ABC", "Fox", "PBS", "A&E", "AMC", "APL", "AXS", "BBC America", "BET", "Bloomberg", "Bravo", "Cartoon Network", "Cinemax", "CMT", "CNBC", "CNN", "Comedy Central", "CSPAN", "CSPAN2", "Discovery", "Disney", "Disney XD", "E!", "Encore", "EPIX", "ESPN", "ESPN2", "ESQTV", "Food Network", "Fox Business", "Fox News", "Fox Sports 1", "Freeform", "FSN", "FSPrime", "FX", "FXX", "FYI", "Game Show Network", "Hallmark", "HBO", "HGTV", "History", "HLN", "ID", "IFC", "ION", "KCAL", "KCET", "KCOP", "KDOC", "KLCS", "KMEX", "KOCE", "KTLA", "Lifetime", "LOGO", "MLB", "MSNBC", "MTV", "National Geographic", "NBCSP", "NFL", "Nickleodeon", "Ovation", "OWN", "Oxygen", "POP", "REELZ", "Showtime", "SN-LA", "SPIKE", "STARZ", "Sundance", "Syfy", "TBS", "TCM", "TLC", "TMC", "TNT", "Travel", "Tru TV", "TV Land", "TVGM", "TW Sports", "USA", "VH1", "WE", "WGN America"}
property picsFolder : ""
property lastDocTitle : ""
property lastCaptionLead : " "
property lastCaptionWriter : "estv"
property lastPhotoSource : ""
property lastPhotoCredit : ""
property lastPhotoAuthor : ""
set menuType to {"TV Series", "TV Mini-series", "TV Movie", "TV Special", "Movie", "Theater", "Music", "Food", "Art"}
set defaultTitle to item 1 of menuTitles
set defaultChannel to item 1 of menuChannels
set defaultType to item 1 of menuType
set tableTitle to "Info for All Photos"
set tablePrompt to "Select from list or enter new value"
set OKButtonName to "Refresh"
set extraButtonName to "Continue"
repeat
set myTable to make new table with data {{defaultTitle, defaultChannel, defaultType}} Ā¬
editable columns {1, 2, 3} Ā¬
column headings {"Title", "Channel", "Program Type"} Ā¬
row template {{combo box, menuTitles}, {combo box, menuChannels}, {popup menu, menuType}} Ā¬
with title tableTitle Ā¬
empty selection allowed true Ā¬
with prompt tablePrompt
modify table myTable Ā¬
OK button is default true Ā¬
OK button name OKButtonName Ā¬
extra button name extraButtonName Ā¬
row dragging false Ā¬
column reordering false Ā¬
initial position lastPosition
tell application "Adobe Photoshop CS6"
set displayResult to display table myTable with extended results
end tell
set {userTitle, userChannel, userType} to item 1 of values returned of displayResult
set whichButton to button number of displayResult
set lastPosition to items 1 thru 2 of final position of displayResult
if item 1 of lastPosition < 10 then set item 1 of lastPosition to 10
if item 2 of lastPosition < 10 then set item 2 of lastPosition to 10
set titleData to userTitle
set leadData to titleData & " -- " & userChannel & " " & userType & ", "
set promptData to "Title: \"" & titleData & "\"" & return & return & leadData
set {defaultTitle, defaultChannel, defaultType} to {userTitle, userChannel, userType}
set tablePrompt to "Select from list or enter new value" & return & return & promptData
if whichButton is 2 then exit repeat
end repeat
if titleData is not in menuTitles then
set item 1 of menuTitles to titleData
set the beginning of menuTitles to ""
if the (count of menuTitles) > 100 then set menuTitles to items 1 thru 100 of menuTitles
end if
if userChannel is not in menuChannels then
set item 1 of menuChannels to userChannel
set the beginning of menuChannels to ""
if the (count of menuChannels) > 100 then set menuChannels to items 1 thru 100 of menuChannels
end if
set docTitle to userTitle
set captionLead to leadData
set captionWriter to "estv"
set photoCredit to userChannel
set photoSource to userChannel
tell application "Adobe Photoshop CS6"
set lastPhotoAuthor to ""
my EstablishFilesFolders()
set extension to ".jpg"
set myDocs to every document
repeat with x from 1 to count of myDocs
repeat 1 times
set thisDoc to document x
tell thisDoc
set allInfo to properties of info
set docName to name
my BringDocTabToFront(docName)
select all
deselect
set programSummary to "\"" & docTitle & "\" on " & photoCredit & "."
set photoCaption to caption of info
set photoCaption to my ReplaceText(programSummary, "", photoCaption)
set photoCaption to my ReplaceText(captionLead, "", photoCaption)
set photoCaption to captionLead & photoCaption & return & return & programSummary
set caption of info to photoCaption
set title of info to docTitle
set caption writer of info to captionWriter
set captionText to caption of info
set credit of info to photoCredit
set source of info to photoSource
set headline of info to programSummary
set fileName to my SlugifyText(docTitle)
set {filePath, uniqueName} to my UniqueFileName(fileName, extension)
end tell
save document x in file filePath as JPEG with options {class:JPEG save options, quality:12}
end repeat
end repeat
end tell
set lastPhotoAuthor to ""
on GetUserChoices(userTitle, userChannel, userType)
set lastDocTitle to userTitle
set titleData to userTitle
set lastCaptionLead to titleData & " -- " & userChannel & " " & userType & ", "
set promptData to "Title: \"" & titleData & "\"" & return & return & lastCaptionLead
set {defaultTitle, defaultChannel, defaultType} to {userTitle, userChannel, userType}
set lastPhotoCredit to userChannel
set lastPhotoSource to userChannel
tell current application
set userList to {}
set AppleScript's text item delimiters to {": "}
set TitleOption to {"Image Title ", lastDocTitle}
set captionOption to {"Caption Lead ", lastCaptionLead}
set authorOption to {"Photo Author ", lastPhotoAuthor}
set creditOption to {"Photo Credit ", lastPhotoCredit}
set sourceOption to {"Photo Source ", lastPhotoSource}
set captionWriterOption to {"Caption Writer ", lastCaptionWriter}
set userList to {TitleOption as text, captionOption as text, creditOption as text, sourceOption as text, authorOption as text, captionWriterOption as text}
--choose from list
set userPrompt to "Select which image info values to change:"
set userListWindow to "Image Info Values"
set UserChoice to choose from list userList Ā¬
with title userListWindow Ā¬
with prompt userPrompt Ā¬
default items {TitleOption as text, captionOption as text, creditOption as text, sourceOption as text} Ā¬
OK button name Ā¬
"These" multiple selections allowed true Ā¬
with empty selection allowed
if UserChoice is false then return ""
if UserChoice is {} then return {lastDocTitle, lastCaptionLead, lastCaptionWriter}
if (TitleOption as text) is in UserChoice then
set docTitle to my AskTheUserForNewInfo(TitleOption)
set lastDocTitle to docTitle
else
set docTitle to lastDocTitle
end if
if (sourceOption as text) is in UserChoice then
set photoSource to my AskTheUserForNewInfo(sourceOption)
set lastPhotoSource to photoSource
else
set photoSource to lastPhotoSource
end if
set UserChoice to choose from list userList Ā¬
with title userListWindow Ā¬
with prompt userPrompt Ā¬
default items {TitleOption as text, captionOption as text, creditOption as text, sourceOption as text} Ā¬
OK button name Ā¬
"These" multiple selections allowed true Ā¬
with empty selection allowed
if (captionOption as text) is in UserChoice then
set captionLead to my AskTheUserForNewInfo(captionOption)
set lastCaptionLead to captionLead
else
set captionLead to lastCaptionLead
end if
if (authorOption as text) is in UserChoice then
set photoAuthor to my AskTheUserForNewInfo(authorOption)
set lastPhotoAuthor to photoAuthor
else
set photoAuthor to lastPhotoAuthor
end if
if (captionWriterOption as text) is in UserChoice then
set captionWriter to my AskTheUserForNewInfo(captionWriterOption)
set lastCaptionWriter to captionWriter
else
set captionWriter to lastCaptionWriter
end if
end tell
if (sourceOption as text) is in UserChoice then
set photoSource to my AskTheUserForNewInfo(sourceOption)
set lastPhotoSource to photoSource
else
set photoSource to lastPhotoSource
end if
if (creditOption as text) is in UserChoice then
set photoCredit to my AskTheUserForNewInfo(creditOption)
set lastPhotoCredit to photoCredit
else
set photoCredit to lastPhotoCredit
end if
return {docTitle, captionLead, captionWriter, photoAuthor, photoSource, photoCredit}
end GetUserChoices
on AskTheUserForNewInfo(entryOption)
set {infoLabel, infoText} to entryOption
--DisplayDialog Full
set dialogPrompt to "Enter the value for " & infoLabel
set dialogDefaultText to infoText
set dialogResult to display dialog dialogPrompt Ā¬
default answer dialogDefaultText Ā¬
with title infoLabel Ā¬
giving up after 600
set newInfo to text returned of dialogResult
return newInfo
end AskTheUserForNewInfo
on UniqueFileName(fileName, extension)
set increment to ""
set incrementInteger to 0
repeat
set trialName to fileName & increment & extension
set trialFilePath to (picsFolder as text) & trialName
try
alias trialFilePath
if increment is "" then
set increment to -1
set incrementInteger to 0
else
set incrementInteger to incrementInteger + 1
set increment to "-" & (incrementInteger as text)
end if
on error
return {trialFilePath, trialName}
end try
end repeat
end UniqueFileName
on EstablishFilesFolders()
set picFolderLocation to path to documents folder as alias
set picsFolder to my EstablishFolder(picFolderLocation, "Pics")
set picsInfoFilePath to (picsFolder as text) & "PicsInfo.txt"
set picInfoFile to my EstablishFile(picsInfoFilePath)
end EstablishFilesFolders
on EstablishFolder(folderPath, myFolderName)
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {""}
set folderLocation to {(folderPath as text), myFolderName, ":"} as text
set AppleScript's text item delimiters to saveTID
try
set folderLocation to alias folderLocation
return folderLocation
on error errorText number errNum
repeat 30 times
tell application "Finder"
try
make new folder at folderPath
set NewFolder to the result as alias
set the name of NewFolder to myFolderName
return NewFolder as alias
on error errorText number errNum
if errNum = -48 then
return NewFolder as alias
else
set myFolderName to myFolderName & "Ę"
end if
end try
end tell
end repeat
end try
end EstablishFolder
--ReplaceTextHandler
on ReplaceText(findString, replaceString, textToFix)
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {findString}
set textToFix to every text item of textToFix
set AppleScript's text item delimiters to {replaceString}
set textToFix to textToFix as text
set AppleScript's text item delimiters to saveTID
return textToFix
end ReplaceText
on EstablishFile(myFile)
local myFile
try
return alias myFile
end try
try
set openFile to open for access file myFile with write permission
on error errText
close access file myFile
set openFile to open for access file myFile with write permission
end try
close access openFile
return myFile as alias
end EstablishFile
on ReplaceAllInText(findString, replaceString, textToFix)
set saveTID to AppleScript's text item delimiters
repeat
set AppleScript's text item delimiters to findString as list
set textToFix to every text item of textToFix
if (count of textToFix) = 1 then
set textToFix to textToFix as text
exit repeat
end if
set AppleScript's text item delimiters to {replaceString}
set textToFix to textToFix as text
if replaceString is in {findString} then exit repeat -- exits after one pass to avoid infinite loop
end repeat
set AppleScript's text item delimiters to saveTID
return textToFix as text
end ReplaceAllInText
on SlugifyText(textToSlugify)
set newText to {}
set textToSlugify to ReplaceAllInText({"'"}, {""}, textToSlugify)
set textToSlugify to ReplaceAllInText({"."}, {""}, textToSlugify)
set textToSlugify to ReplaceAllInText({","}, {"-"}, textToSlugify)
set textToSlugify to ReplaceAllInText({"!"}, {""}, textToSlugify)
set textToSlugify to ReplaceAllInText({"?"}, {""}, textToSlugify)
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {""}
set textToSlugify to text items of textToSlugify
repeat with thisitem in textToSlugify
if (thisitem as text) is in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890-_" then
set the end of newText to thisitem as text
else
set the end of newText to "-"
end if
end repeat
if newText is not {} then
set newText to newText as text
set newText to my ReplaceAllInText("_", "-", newText)
set newText to my ReplaceAllInText("--", "-", newText)
else
set newText to "slug"
end if
set AppleScript's text item delimiters to saveTID
return newText
end SlugifyText
on BringDocTabToFront(myDocName)
tell application "Adobe Photoshop CS6" to activate
tell application "System Events"
tell process "Photoshop"
click menu item myDocName of menu 1 of menu bar item "Window" of menu bar 1
end tell
end tell
delay 1
end BringDocTabToFront
The current version limits the prompt to an initial four lines. Iāll see if bumping that up has any nasty side-effects. Meanwhile you can avoid the problem by removing one of your returns.
That text has returns? Yikes!
Removing the returns did the trick. The returns were just to make it look nicer when I was using display dialog.
I also noticed something in a different script that is a bit of an annoyance. The script runs from the Apple Scripts menu, and displays a table giving the user options. When the user clicks OK the script continues, but the table stays up until the script quits. Since this script takes a good while to execute thatās a bit annoying.
Try it with FastScripts. Myriad Tables ā and any library that uses a third-party framework ā wonāt run, period, from Appleās Scripts menu as of macOS 10.14.
Iād have to install FastScripts on all the macs in our department, and I hate doing that.
Hey Ed,
How many Macs is that?
-Chris