Welcome to MacTalk Australia

the largest Australian community for Apple discussions and topics

» Join the discussions, Register Now!
Results 1 to 5 of 5
  1. #1

    Join Date
    Dec 2004
    Location
    Newcastle
    Posts
    2,373

    Default

    Hey guys, maybe you could help me with this. How do I add a cancel button to this particular applescript? I have also attached the actual script as well. Thanks. Jeff.

    Code:
    -- GUI Scripting Demonstration
    --
    -- Modify Keyboard System Preferences to swap the Option (Alt) and Command (Windows) keys
    -- so their placement on the keyboard matches that of the standard Macintosh keyboard. This
    -- will also allow us to change the preferences back so the keys go back to normal
    -- when the PC keyboard is disconnected.
    
    on setKeyboard(keyboardType)
    	tell application "System Events"
     *get properties
     *tell process "System Preferences"
     *	-- click "Modifier Keys..." at bottom of Keyboard tab
     *	click button "Modifier Keys…" of tab group 1 of window "Keyboard & Mouse"
     *	
     *	if keyboardType is equal to "Macintosh" then
     * *-- click "Restore Defaults" on the sheet
     * *click button "Restore Defaults" of sheet 1 of window "Keyboard & Mouse"
     * *
     *	else if keyboardType is equal to "PC" then
     * *-- click the pop up button menu "Option", this menu does not exist until it is clicked in the GUI
     * *click pop up button 3 of sheet 1 of window "Keyboard & Mouse"
     * *-- click "Command" of the pop up menu
     * *click menu item 4 of menu 1 of pop up button 3 of sheet 1 of window "Keyboard & Mouse"
     * *
     * *-- delay briefly
     * *delay 1
     * *
     * *-- click the pop up button menu "Command", this menu does not exist until it is clicked in the GUI
     * *click pop up button 4 of sheet 1 of window "Keyboard & Mouse"
     * *-- click "Option" of the pop up menu
     * *click menu item 3 of menu 1 of pop up button 4 of sheet 1 of window "Keyboard & Mouse"
     *	end if
     *	
     *	-- click "OK" to dismiss the sheet
     *	click button "OK" of sheet 1 of window "Keyboard & Mouse"
     *end tell
    	end tell
    end setKeyboard
    
    -- main script; preset desiredKeyboard to "Macintosh"
    set desiredKeyboard to "Macintosh"
    
    -- get users input; we're waiting until selection
    display dialog "Which keyboard type?" buttons {"Macintosh", "PC"} with icon 2 default button "Macintosh"
    
    -- set desiredKeyboard to "PC" if they picked "PC"
    if button returned of result = "PC" then
    	set desiredKeyboard to "PC"
    end if
    
    -- activate System Preferences
    tell application "System Preferences"
    	activate
    	set current pane to pane "com.apple.preference.keyboard"
    end tell
    
    -- call subroutine with desired keyboard type
    setKeyboard(desiredKeyboard)
    
    -- quit from system preferences
    tell application "System Preferences"
    	quit
    end tell

  2. #2

    Join Date
    Jul 2005
    Location
    Melbourne
    Posts
    1,126

    Default

    you need
    Code:
    display dialog "Which keyboard type?" buttons {"Macintosh", "PC", "cancel"} with icon 2 default button "Macintosh"
    
    if button returned of result = "cancel" then
    tell application "System Preferences" 
    quit
    end tell
    my applescripting is a bit rusty. but that seems to be the way i remember it.

    there is also an applescript dictionary in script editor that should give you all the low down. its under the file menu. (apple shift O)

    W2ttsy

  3. #3

    Join Date
    Dec 2004
    Location
    Newcastle
    Posts
    2,373

    Default

    It didnt work. See the Attachment...

  4. #4

    Join Date
    Dec 2004
    Location
    Newcastle
    Posts
    2,373

    Default

    Thank You niteshade for fixing this over IRC for me.

    I have to change this:

    Code:
    display dialog "Which keyboard type?" buttons {"Macintosh", "PC"} with icon 2 default button "Macintosh"
    To This:

    Code:
    display dialog "Which keyboard type?" buttons {"Cancel", "PC", "Macintosh"} with icon caution default button 3 cancel button 1 with title "Choose a Keyboard"
    Thank you once again niteshade!

  5. #5

    Join Date
    Dec 2004
    Location
    Newcastle
    Posts
    2,373

    Default

    This is the new improved script which does not mess with your caps lock and control keyboard settings. Once again the source is right here and the file is attached! Have Fun.

    Code:
    -- GUI Scripting Demonstration
    --
    -- Modify Keyboard System Preferences to swap the Option (Alt) and Command (Windows) keys
    -- so their placement on the keyboard matches that of the standard Macintosh keyboard. This
    -- will also allow us to change the preferences back so the keys go back to normal
    -- when the PC keyboard is disconnected.
    
    on setKeyboard(keyboardType)
    	tell application "System Events"
     *get properties
     *tell process "System Preferences"
     *	-- click "Modifier Keys..." at bottom of Keyboard tab
     *	click button "Modifier Keys…" of tab group 1 of window "Keyboard & Mouse"
     *	
     *	if keyboardType is equal to "Macintosh" then
     * *-- click the pop up button menu "Command", this menu does not exist until it is clicked in the GUI
     * *click pop up button 3 of sheet 1 of window "Keyboard & Mouse"
     * *-- click "Option" of the pop up menu
     * *click menu item 3 of menu 1 of pop up button 3 of sheet 1 of window "Keyboard & Mouse"
     * *
     * *-- delay briefly
     * *delay 1
     * *
     * *-- click the pop up button menu "Option", this menu does not exist until it is clicked in the GUI
     * *click pop up button 4 of sheet 1 of window "Keyboard & Mouse"
     * *-- click "Command" of the pop up menu
     * *click menu item 4 of menu 1 of pop up button 4 of sheet 1 of window "Keyboard & Mouse"
     *	end if
     *	
     *	if keyboardType is equal to "PC" then
     * *-- click the pop up button menu "Option", this menu does not exist until it is clicked in the GUI
     * *click pop up button 3 of sheet 1 of window "Keyboard & Mouse"
     * *-- click "Command" of the pop up menu
     * *click menu item 4 of menu 1 of pop up button 3 of sheet 1 of window "Keyboard & Mouse"
     * *
     * *-- delay briefly
     * *delay 1
     * *
     * *-- click the pop up button menu "Command", this menu does not exist until it is clicked in the GUI
     * *click pop up button 4 of sheet 1 of window "Keyboard & Mouse"
     * *-- click "Option" of the pop up menu
     * *click menu item 3 of menu 1 of pop up button 4 of sheet 1 of window "Keyboard & Mouse"
     *	end if
     *	
     *	-- click "OK" to dismiss the sheet
     *	click button "OK" of sheet 1 of window "Keyboard & Mouse"
     *end tell
    	end tell
    end setKeyboard
    
    -- main script; preset desiredKeyboard to "Macintosh"
    set desiredKeyboard to "Macintosh"
    
    -- get users input; we're waiting until selection
    display dialog "Which keyboard type?" buttons {"Macintosh", "PC", "Cancel"} with icon caution default button 3 cancel button 3 with title "iKeyboard"
    
    -- set desiredKeyboard to "PC" if they picked "PC"
    if button returned of result = "PC" then
    	set desiredKeyboard to "PC"
    end if
    
    -- activate System Preferences
    tell application "System Preferences"
    	activate
    	set current pane to pane "com.apple.preference.keyboard"
    end tell
    
    -- call subroutine with desired keyboard type
    setKeyboard(desiredKeyboard)
    
    -- quit from system preferences
    tell application "System Preferences"
    	quit
    end tell

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •