Applescript pictures

Hello. My brother wants to make a quiz, using AppleScript. The way he wants the quiz to work is that a picture pops up, and you are gonna write who it is. I know how to write text into a dialog box (display dialog "Text" default answer "answer" buttons {"1","2"}) but I'm not sure how to insert a picture into an AppleScript script. For example, if you are running the script, there should pop up a picture of a football player, and a dialog box that says something like "Who is this?". Is this possible in AppleScript?

Thank you for answers

MacBook (Retina, 12-inch, Early 2016), iOS 10.2.1

Posted on Mar 12, 2017 11:24 AM

Reply
4 replies

Mar 15, 2017 10:32 AM in response to Frosken3

One option is to use Carsten Blüm's Pashua with AppleScript.

User uploaded file

User uploaded file

User uploaded file

Sample script:


--Note: This script is modified from the original example by the user.

(*

This example loads script "Pashua.scpt" (to be compiled from "Pashua.applescript") from the

same folder which contains this file. Pashua.scpt handles the communcation with Pashua.app.

You can either take the handlers out of Pashua.scpt and use them inline whenever you write

a script which uses Pashua, use Pashua.scpt as an AppleScript Library (OS X 10.9 or newer)

or use the "load script" approach used in this file.

*)

-- Get the path to the folder containing this script

tell application "Finder"

set thisFolder to (container of (path to me)) as string

if "Pashua:Pashua.app:" exists then

-- Looks like the Pashua disk image is mounted. Run from there.

set customLocation to "Pashua:"

else

-- Search for Pashua in the standard locations

set customLocation to ""

end if

end tell

try

set thePath to alias (thisFolder & "Pashua.scpt")

set pashuaBinding to load script thePath

tell pashuaBinding

-- Display the dialog

try

set pashuaLocation to getPashuaPath(customLocation)

set dialogConfiguration to my getDialogConfiguration(pashuaLocation)

set theResult to showDialog(dialogConfiguration, customLocation)

-- Display the result. The record keys ("... of theResult") are defined in the

-- dialog configuration string.

if {} = theResult then

display alert "Empty return value" message "It looks like Pashua had some problems using the window configuration." as warning

else if cb of theResult is not "1" and "Adrian Peterson" = tf of theResult then

display alert "Right On!" message "Adrian Peterson is the correct answer."

else if cb of theResult is not "1" and "" ≠ tf of theResult then

display alert "Oops!" message tf of theResult & " is not the correct answer." & return & return & "The correct answer is Adrian Peterson"

else if cb of theResult is not "1" and "" = tf of theResult then

display dialog "The dialog was closed without submitting the values"

else

-- The cancelbutton (named "cb" in the config string) was pressed

display dialog "The dialog was cancelled"

end if

on error errorMessage

display alert "An error occurred" message errorMessage as warning

end try

end tell

on error errStr number errorNumber

display dialog errStr

end try


-- Returns the configuration string for an example dialog

on getDialogConfiguration(pashuaLocation)


if pashuaLocation is not "" then

set img to "img.type = image

img.x = 0

img.y = 100

img.maxwidth = 600

img.tooltip = This is an element of type “image”

img.path = " & ("/Users/pd/Desktop/peterson.JPG") & return

--substitute the file path to an image where it is stored on your computer

else

set img to ""

end if

return "


# Set window title

*.title = Quiz

# Add a text field

tf.type = textfield

tf.label = Name this football player:

tf.width = 300


# Add a cancel button with default label

cb.type = cancelbutton


" & img

end getDialogConfiguration


Pashua Documentation


Sample scripts are included in the Pashua download. Install Pashua into your Applications folder. It's important to note that your compiled Applescript (.scpt) and the compiled Pashua.scpt are required to reside in the same folder if using the load script approach used in the script above.


Tested with OS X Yosemite 10.10.5, Script Editor 2.7, AppleScript 2.4, Pashua 0.10.3

Mar 18, 2017 10:23 PM in response to Frosken3

You're welcome. Btw, if you have user interface sound effects enabled, the sound on, and are annoyed by the playing of 'move to trash.aif’ every time you run your script, the culprit is located in Pashua.scpt. When run, it creates a temporary file with the configuration string which it subsequently deletes by sending it to Trash. The remedy is to comment out the appropriate line responsible by preceding it with two consecutive hyphens:


-- tell application "Finder" to delete tmpfile


Recompile and save. It’s not necessary for the temporary file to be sent to Trash on every use, the TemporaryItems folder will clear on reboot.

User uploaded file

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript pictures

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.