soundart11

Q: Emulating pressing F6 & F7 together with Applescript

I've been trying to create an Applescript for toggle to the Smart Tool in Pro Tools 10 & 11.  The key command within Pro Tools is pressing F6&F7 together.  All I can get to happen is two separate presses which just toggle other tools within Pro Tools.  My closest attempt is:

 

tell application "Pro Tools" to activate

 

tell application "System Events"

key down (key code 97)

key code 98

end tell

 

I've tried other variations without success.  Any help would be greatly appreciated.

Mac mini (Late 2012), OS X Mountain Lion (10.8.3)

Posted on Aug 1, 2013 10:20 AM

Close

Q: Emulating pressing F6 & F7 together with Applescript

  • All replies
  • Helpful answers

  • by xnav,

    xnav xnav Aug 1, 2013 11:03 AM in response to soundart11
    Level 5 (6,640 points)
    Aug 1, 2013 11:03 AM in response to soundart11

    Did you try?

     

    tell application "System Events"

      key down {key code 97, key code 98}

    end tell

  • by soundart11,

    soundart11 soundart11 Aug 1, 2013 11:05 AM in response to xnav
    Level 1 (0 points)
    Aug 1, 2013 11:05 AM in response to xnav

    Thanks, but I still get the same result of 2 seperate key strokes.

  • by Hiroto,

    Hiroto Hiroto Aug 1, 2013 1:51 PM in response to soundart11
    Level 5 (7,281 points)
    Aug 1, 2013 1:51 PM in response to soundart11

    Hello

     

    You may try the script below.

    I have tested RubyCocoa code but not the whole script, for I don't have Pro Tools or any application which accepts two F keys simultaneously.

     

    Good luck,

    H

     

    tell application "Pro Tools" to activate
    
    do shell script "/usr/bin/ruby <<'EOF'
    require 'osx/cocoa'
    include OSX
    
    k1d = CGEventCreateKeyboardEvent(nil, 0x0061, true)     # F6 keydown
    k1u = CGEventCreateKeyboardEvent(nil, 0x0061, false)    # F6 keyup
    k2d = CGEventCreateKeyboardEvent(nil, 0x0062, true)     # F7 keydown
    k2u = CGEventCreateKeyboardEvent(nil, 0x0062, false)    # F7 keyup
    
    tap = KCGHIDEventTap
    CGEventPost(tap, k1d)
    CGEventPost(tap, k2d)
    CGEventPost(tap, k1u)
    CGEventPost(tap, k2u)
    EOF"
    
  • by soundart11,

    soundart11 soundart11 Aug 1, 2013 1:54 PM in response to Hiroto
    Level 1 (0 points)
    Aug 1, 2013 1:54 PM in response to Hiroto

    Thanks Hiroto, but once again I get the same result.

  • by Hiroto,

    Hiroto Hiroto Aug 1, 2013 5:54 PM in response to soundart11
    Level 5 (7,281 points)
    Aug 1, 2013 5:54 PM in response to soundart11

    Then try inserting small delay in key down and key up events. Like this -

     

    tell application "Pro Tools" to activate
    
    do shell script "/usr/bin/ruby <<'EOF'
    require 'osx/cocoa'
    include OSX
    
    k1d = CGEventCreateKeyboardEvent(nil, 0x0061, true)     # F6 keydown
    k1u = CGEventCreateKeyboardEvent(nil, 0x0061, false)    # F6 keyup
    k2d = CGEventCreateKeyboardEvent(nil, 0x0062, true)     # F7 keydown
    k2u = CGEventCreateKeyboardEvent(nil, 0x0062, false)    # F7 keyup
    
    tap = KCGHIDEventTap
    CGEventPost(tap, k1d)
    CGEventPost(tap, k2d)
    sleep 0.2
    CGEventPost(tap, k1u)
    CGEventPost(tap, k2u)
    EOF"
    
  • by soundart11,

    soundart11 soundart11 Aug 1, 2013 7:57 PM in response to Hiroto
    Level 1 (0 points)
    Aug 1, 2013 7:57 PM in response to Hiroto

    Still the same result.  I appreciate the effort though!!

  • by Bernard Harte,

    Bernard Harte Bernard Harte Aug 2, 2013 6:07 AM in response to soundart11
    Level 4 (3,309 points)
    iPhone
    Aug 2, 2013 6:07 AM in response to soundart11

    I don't have ProTools either, but have you tried:

     

    (after activating ProTools)

     

    tell application "System Events"

      key down (key code 97)

      key down (key code 98)

      delay 10 -- or do whatever needs to happen

      key up (key code 98)

      key up (key code 97)

    end tell

  • by Hiroto,Helpful

    Hiroto Hiroto Aug 2, 2013 9:11 AM in response to soundart11
    Level 5 (7,281 points)
    Aug 2, 2013 9:11 AM in response to soundart11

    Hmm. You mean it acts as if F6 was pressed and released and then F7 was pressed and released even though evens are posted differently? Then I'd guess Pro Tools is doing something special when interpretting events sequence. I give up pursuing this route.

     

    There's good news, though. According to some resources, there're other keyboard shortcuts for Smart Tool which are F7+F8 and command+7. So you may simply use System Events' key code command for command+7 as listetd below. The key code for 7 (on keyboard not on keypad) is 0x1A (26) on English keyboard. It may vary on different keyboard hardware layout for other languages.

     

    cf.

    http://www.protoolskeyboardshortcuts.com/pro-tools-10-keyboard-shortcuts/

    http://www.protoolskeyboardshortcuts.com/pro-tools-11-keyboard-shortcuts/

     

    (*
        Smart Tool shortcuts = F6+F7, F7+F8 or command+7 (on keyboard)
    *)
    tell application "Pro Tools" to activate
    tell application "System Events"
        key code 26 using command down -- 0x1a (26) =>  7 on (English) keyboard, not on keypad
    end tell
    

     

    Regards,

    H

  • by stevemonty,

    stevemonty stevemonty Sep 16, 2014 12:26 PM in response to soundart11
    Level 1 (0 points)
    Sep 16, 2014 12:26 PM in response to soundart11

    Hiroto has it right.