Advertisement
asselinpaul

Help with Applescript

Jan 6th, 2012
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  I need help with extension writing in Applescript for Alfred.
  2. This following script works, it sets the mouse sensitivity to 5.
  3.  
  4. ////////////////////////////////////////////////////////////////////
  5.  
  6. set trackingValue to 5
  7.  
  8. --Open and activate System Preferences
  9. tell application "System Preferences" to activate
  10.  
  11. --Attempt to change settings using System Events
  12. tell application "System Events"
  13.         tell process "System Preferences"
  14.                 try
  15.                         --Open the "Keyboard & Mouse" pane
  16.                         click menu item "Mouse" of menu "View" of menu bar 1
  17.                         delay 2
  18.                         set value of slider "Tracking Speed" of window "Mouse" to trackingValue
  19.                         --end tell
  20.                 on error theError
  21.                         --An error occured
  22.                         display dialog ("Sorry, an error occured while altering Keyboard and Mouse settings:" & return & theError) buttons "OK" default button "OK"
  23.                        
  24.                 end try
  25.                
  26.         end tell
  27.        
  28. end tell
  29.  
  30. if application "System Preferences" is running then
  31.         tell application "System Preferences" to quit
  32. end if  
  33. ////////////////////////////////////////////////////////////////////////////////////////
  34.  
  35. I want to make an extension for Alfred which does the same thing but the user can specify the value.
  36.  
  37. What's wrong with this? i don't know much about Applescript and thought you might be able to help me. Thanks in advance anyway.
  38.  
  39. ///////////////////////////////////////////////////////////////////////////////////////
  40. on alfred_script(q)
  41.  
  42.     set trackingValue to q
  43.    
  44.     --Open and activate System Preferences
  45.     tell application "System Preferences" to activate
  46.    
  47.     --Attempt to change settings using System Events
  48.     tell application "System Events"
  49.         tell process "System Preferences"
  50.             try
  51.                 --Open the "Keyboard & Mouse" pane
  52.                 click menu item "Mouse" of menu "View" of menu bar 1
  53.                 delay 2
  54.                 set value of slider "Tracking Speed" of window "Mouse" to trackingValue
  55.                 --end tell
  56.             on error theError
  57.                 --An error occured
  58.                 display dialog ("Sorry, an error occured while altering Keyboard and Mouse settings:" & return & theError) buttons "OK" default button "OK"
  59.                
  60.             end try
  61.            
  62.         end tell
  63.        
  64.     end tell
  65.    
  66.     if application "System Preferences" is running then
  67.         tell application "System Preferences" to quit
  68.     end if
  69. end alfred_script
  70.  
  71. ////////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement