Make sure whatever app is executing the script has full disk access
Try the following (from Stefan). Make sure the path is correct. Tested on Ventura.
set theFile to "Macintosh HD:Users:shawnbrady:Desktop:Bingo Balls GFX:B11.jpg" -- user set as desired
tell application "Finder" to set theURL to URL of file theFile
open location theURL
Yes. I forgot, exists known bug when the Finder can’t open some files (files which was not opened manually before in the Finder). The workaround is shown by @peavine. You can do this as well:
tell application "Finder"
set theURL to URL of document file (randomChoice & ".jpg") of folder "Bingo Balls GFX" of desktop
tell me to open location theURL
end tell
You can omit “of desktop” in the 2nd code line, because the desktop is default root folder for the Finder.
I did enjoy typing “Bingo hackers”!
FTW!
I think your other point is maybe even more pertinent:
I suppose it’s a bit of skeuomorphic programing.
Too many times, people try to write AppleScripts to replicate the real-world way of doing things - whether that’s selecting a bingo ball from a bucket, or clicking on a menu item with the mouse , or even set the clipboard to something and invoking paste
Sometimes that’s all you have, especially with applications that don’t have robust AppleScript support, but often AppleScript is works best when you look at what you’re trying to do, not necessarily regurgitating how you’d do it in the real world - in this case, determine a (pseudo-)random set of unique items from a predefined list.
Here’s a solution that uses Shane’s Myriad Tables Library:
Freeware | Late Night Software (Myriad Tables Lib)
Myriad Tables Lib is an AppleScript script library that gives AppleScript scripts the ability to show dialogs containing tables. It requires OS X 10.10 or later. Note that scripts using Myriad Tables Lib cannot be edited in Script Editor in Mojave or later because of new security settings. You need to use Script Debugger. See Catalina Security and Script Libraries for Catalina installation details. (updated February 9, 2023)
use AppleScript version "2.4"
use scripting additions
use script "Myriad Tables Lib" version "1.0.12"
set numberRequired to 75
property bingoTable : {}
set bingo_numbers to GetBingoNumbers()
copy bingo_numbers to called_numbers
repeat with i from 1 to (count bingo_numbers)
set item i of called_numbers to i
end repeat
BuildNewBingoTable()
repeat numberRequired times
set i to some integer of called_numbers
set thisNumber to item i of bingo_numbers
set item i of called_numbers to thisNumber
set currentCount to count of text of called_numbers
--display table with data
set {userButton} to PopulateBingoTable(thisNumber, currentCount)
if userButton is 0 then exit repeat
end repeat
return text of called_numbers
on GetBingoNumbers()
set bingoLetters to characters of "BINGO"
set bingoNumbers to {}
set x to 0
repeat with thisLetter in bingoLetters
repeat 15 times
set x to x + 1
set the end of bingoNumbers to thisLetter & "-" & x as text
end repeat
end repeat
return bingoNumbers
end GetBingoNumbers
on BuildNewBingoTable()
set bingoTable to {{}, {}, {}, {}, {}}
repeat with x from 1 to count of bingoTable
repeat 15 times
set the end of item x of bingoTable to ""
end repeat
end repeat
set bingoTable to swap columns and rows in bingoTable
end BuildNewBingoTable
on PopulateBingoTable(theNumber, currentCount)
local calledNumbers, whichColumn, theRow
set tableRecord to {tableData:{}, tableTitle:"", tablePrompt:"", multipleLinesAllowed:true, multipleSelectionsAllowed:true, emptySelectionAllowed:true, canAddAndDelete:true, rowNumbering:true, editableColumns:{}, columnHeadings:{""}, initiallySelectedRows:{}, rowTemplate:{}, doubleClickable:true, giveUpAfter:60}
set {theColumn, theValue} to words of theNumber
if theColumn is "B" then
set whichColumn to 1
set theRow to (theValue as integer)
else if theColumn is "I" then
set whichColumn to 2
set theRow to (theValue as integer) - 15
else if theColumn is "N" then
set whichColumn to 3
set theRow to (theValue as integer) - 30
else if theColumn is "G" then
set whichColumn to 4
set theRow to (theValue as integer) - 45
else if theColumn is "O" then
set whichColumn to 5
set theRow to (theValue as integer) - 60
end if
set item whichColumn of item theRow of bingoTable to theNumber
tell tableRecord
set its tableData to bingoTable
set its tableTitle to "Current call: " & theNumber
set its tablePrompt to "Current call: " & theNumber & return & return & currentCount & " of 75 numbers called"
set its multipleLinesAllowed to false --trueOrFalse
set its multipleSelectionsAllowed to false --trueOrFalse
set its emptySelectionAllowed to true --trueOrFalse
set its canAddAndDelete to false --trueOrFalse
set its rowNumbering to true --trueOrFalse
set its editableColumns to missing value
set its columnHeadings to {"B", "I", "N", "G", "O"}
set its initiallySelectedRows to {}
set its doubleClickable to true --trueOrFalse
end tell
set {buttonNumber} to my DisplayMTTableWithData(tableRecord, theRow)
return {buttonNumber}
end PopulateBingoTable
on DisplayMTTableWithData(tableRecord)
tell tableRecord
set tableData to its tableData
set tableTitle to its tableTitle
set tablePrompt to its tablePrompt
set multipleLinesAllowed to its multipleLinesAllowed
set multipleSelectionsAllowed to its multipleSelectionsAllowed
set emptySelectionAllowed to its emptySelectionAllowed
set canAddAndDelete to its canAddAndDelete
set rowNumbering to its rowNumbering
set editableColumns to its editableColumns
set columnHeadings to its columnHeadings
set initiallySelectedRows to its initiallySelectedRows
set doubleClickable to its doubleClickable
set giveUpAfter to its giveUpAfter
end tell
set verifyMode to false
repeat
if verifyMode then
set tableTitle to "Did someone say \"Bingo!\"?"
set tablePrompt to "Are you sure it's a Bingo? " & return & return & "Clicking yes will erase the current list of called numbers."
set OKButtonName to "Next Number"
set cancelButtonName to ("Yes, It's a Bingo!")
set extraButtonName to ("No Bingo, keep going")
else
set OKButtonName to "Next Number"
set cancelButtonName to "Bingo!"
set extraButtonName to "Bingo?"
end if
set bingoDisplayTable to make new table with data tableData ¬
with title tableTitle ¬
with prompt tablePrompt ¬
multiple selections allowed multipleSelectionsAllowed ¬
empty selection allowed emptySelectionAllowed ¬
can add and delete canAddAndDelete ¬
row numbering rowNumbering ¬
editable columns editableColumns ¬
column headings columnHeadings ¬
initially selected rows initiallySelectedRows ¬
set columnsWidth to 50
set sortingStyle to sort case insensitive --sort as Finder:sort case insensitive:sort case sensitive:sort localized case insensitive:sort localized case sensitive:sort none
set columnsList to {1, 2, 3, 4, 5}
set headAlignment to align left
set entryAlignment to align center
set boldType to true
modify columns in table bingoDisplayTable ¬
columns list columnsList ¬
column width columnsWidth ¬
head alignment headAlignment ¬
bold type boldType ¬
entry alignment entryAlignment
set OKButtonIsDefault to true --trueOrFalse
set alternateBackgrounds to true --trueOrFalse
set rowDragging to false
set columnReordering to false
set gridStyle to grid both
set highlightedRows to {}
modify table bingoDisplayTable ¬
OK button name OKButtonName ¬
OK button is default OKButtonIsDefault ¬
cancel button name cancelButtonName ¬
grid style gridStyle ¬
highlighted rows highlightedRows ¬
alternate backgrounds alternateBackgrounds
try
set tableResult to display table bingoDisplayTable ¬
with extended results
set buttonNumber to button number of tableResult
set finalPosition to final position of tableResult
set verifyMode to false
exit repeat
on error errText number errNum
if verifyMode then return {0}
set verifyMode to true
end try
end repeat
return {buttonNumber}
end DisplayMTTableWithData
I cant even begin to thank you enough, now my BINGO game runs perfectly, and exactly as I need it to. Thank you so much.
I downloaded Myriad Tables Lib…how do I get it to work. Where do I put the scptd file. It also says to use scripting additions…how do I get that to work also. Thanks.
Myriad Tables is included in Shane’s Script Library pack or as a seperated download here: Freeware | Late Night Software
Whichever you install should go in the Script Libraries folder of the Library folder for either the user of or the system ( I prefer the user’s Script Library folder). If you’re using Shane’s Script Library app, you need to run it one time before the system sees it.
Here’s a quick script that will open the folder. Drag the Library or the app here, and if you use the App, launch it one time from within this folder.
set scriptLibraryFolder to (libraryFolder as text) & "Script Libraries"
tell application "Finder"
activate
try
open item scriptLibraryFolder
on error
set scriptLibraryFolder to make new folder at libraryFolder with properties {name:"Script Libraries"}
open item scriptLibraryFolder
end try
end tell