O'Reilly logo

Beginning Mac OS® X Programming by Drew McCormack, Michael Trent

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A.12. Chapter 12

A.12.1. Exercise 1 solution

Insert the following handler code into the slide show script:

on prompt_for_slide_duration()
    set slide_duration to 0
    repeat while slide_duration is 0
        try
            display dialog ¬
                "How many seconds should each slide in the " & ¬
                "slideshow be displayed?" ¬
                buttons {"OK"} default answer 2 default button 1
            set dialog_result to result
            set slide_duration to (text returned of dialog_result) as real
            if slide_duration    0 then error "Enter a positive number"
        on error msg
            display_error_message(msg)
            set slide_duration to 0
        end try
    end repeat
    return slide_duration
end prompt_for_slide_duration

This handler is very similar to others in the script that prompt the user for input. A dialog is displayed requesting the user to enter the number of seconds per slide in the show. The value entered must be a number greater than zero; otherwise an error will arise, and the user will be prompted again.

To complete the exercise, modify the run handler to call the prompt_for_slide_duration handler, and pass the result to the create_image_sequence_from_folder handler.

on run
    try
        copy Photo_Archive to photo_arch
        set photo_arch's archive_folder_name to "Test Photo Archive"
        tell photo_arch to setup_archive_folder()
set num_photos to prompt_for_number_of_photos_in_show() set slide_duration to prompt_for_slide_duration() set the_album to prompt_for_album_choice() add_photos_from_album given Photo_Archive:photo_arch, ¬ album:the_album, number_of_photos:num_photos create_image_sequence_from_folder(photo_arch's ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required