dfay Posted January 27, 2015 Posted January 27, 2015 (edited) Alfred Remote combined with Apple's built-in Dictation seems to have amazing potential. First, set up the following script in Alfred Remote: 1. Start Alfred Preferences 2. Click Remote 3. Click System Commands (or wherever you want to put the commandon your remote) 4. Click one of the + signs on the grid 5. Select Run Script from the pop-up menu 6. In the window that opens, set the Language drop-down to /usr/bin/osascript 7. In the script field, paste in the following short Applescript: tell application "System Events" -- mute volume while dictating, or turn it back on when done -- optionally one could add commands here to play/pause iTunes etc. here set myVolume to get volume settings if output muted of myVolume is false then set volume with output muted else set volume without output muted end if -- toggle dictation key code 63 -- fn key code 63 end tell I then added this icon as well: https://ntk.me/assets/img/2012/12/17/dictation/icon.png Second, if you don't have it enabled already, turn on Dictation and enable Advanced Commands as described here: http://support.apple.com/en-us/HT203085 Now you can use Alfred Remote to turn on Dictation, Show Alfred (or your custom search, workflow, etc.), speak your search terms, (optionally edit as necessary with advanced dictation commands), then speak the command "Press Return key". Magical. Now....this could be even more awesome if Alfred could turn on Dictation then redirect the iPhone microphone to the Mac audio input...then I could stand at the back of my classroom with 500 students and run my laptop on the podium.... Edited January 31, 2015 by dfay
dfay Posted January 27, 2015 Author Posted January 27, 2015 (edited) You can also add Advanced Commands to Dictation via Automator workflows in Yosemite (see http://www.macworld.com/article/2834532/ok-mac-using-automators-dictation-commands-new-in-yosemite.html for an overview). Here are a pair which add commands to Hold and Release the Control key (useful for Alfred workflows that offer options when Control is down). (I also describe how to do this from Alfred Remote here: http://www.alfredforum.com/topic/5414-sending-keyboard-modifiers-ctrl-etc/ ). Edited January 27, 2015 by dfay
mamahuhu Posted January 29, 2015 Posted January 29, 2015 Hi dfay, Thanks a lot, this is amazing! I'm new to this - I'd like to add one action to your script, but I'm having trouble with Apple Script and key strokes. The idea would be to open the Alfred window at the same time as dictation is activated, allowing dictation in the search box right away. As my shortcut is set top option+space, i tried the adding one line as shown below but no dice - it breaks your script functionality. key code 58 using {Space} key code 63 -- fn key code 63 Could you help? Thanks!
rice.shawn Posted January 29, 2015 Posted January 29, 2015 People are going a bit too wild with trying to send key codes rather than using native AppleScript functionality (I'm seeing this in multiple threads). If you have shortcuts that link to some functionality, it's always better for your code to aim for the functionality rather than the shortcuts. It makes the code more reliable, especially because hot keys are context dependent, can easily be remapped, and depend (sometimes) on a certain keyboard layout. So, if you're trying to get Alfred to show, don't send the keycodes to launch Alfred. Instead, launch Alfred with the command: tell application "Alfred 2" to search "" That will always work.
DrLulz Posted January 31, 2015 Posted January 31, 2015 (edited) Doing a Skim search with dictation and then advancing page results with Alfred remote. 1. Remote Trigger --> Keyword 2. Dictate Query --> Skim Search Applescript 3. Use Run Script on the Remote to advance page results. (icon) The search Applescript is "listening" (not really, but you get the idea) for keypress with: on isControlKeyPressed() return (do shell script "/usr/bin/python -c 'import Cocoa; print Cocoa.NSEvent.modifierFlags() & Cocoa.NSControlKeyMask > 1'") is "True" end isControlKeyPressed To advance the page use: tell application id "sevs" control key down delay 0.2 control key up end tell Edited January 31, 2015 by DrLulz
DrLulz Posted January 31, 2015 Posted January 31, 2015 I borrowed my wife's LG bluetooth headset (she gave me a weird look). I was clear across the room (~10m) using Alfred Remote triggers with the headset mic for dictation. Neat!
HehMan Posted January 31, 2015 Posted January 31, 2015 (edited) This sounds awesome. Can someone simplify all the steps and code to use this? I am not savvy enough to follow the details and implement it. If not, perhaps Vero can do a detailed post on it. I am so excited by Alfred Remote and use it all the time now. Edited January 31, 2015 by HehMan
dfay Posted January 31, 2015 Author Posted January 31, 2015 I've updated the original post with a more verbose version. Hopefully that will be more clear. I'm not sure that it can be simplified further– –I guess one could create a workflow but that seems like overkill for a single command.
dfay Posted January 31, 2015 Author Posted January 31, 2015 (edited) @DrLulz I was curious to see if this can be done entirely in a native AppleScript version or at least cutting out the python by using AppleScriptObjC.... I got the following parsimonious bit of code to work in Script Editor, but I haven't had time to try to import it as a library into your script: use framework "Cocoa" on isControlKeyPressed() current application's NSEvent's modifierFlags as integer = current application's NSControlKeyMask end isControlKeyPressed delay 3 isControlKeyPressed() (last two lines are just there for testing purposes) Doing a Skim search with dictation and then advancing page results with Alfred remote. 1. Remote Trigger --> Keyword 2. Dictate Query --> Skim Search Applescript 3. Use Run Script on the Remote to advance page results. (icon) The search Applescript is "listening" (not really, but you get the idea) for keypress with: on isControlKeyPressed() return (do shell script "/usr/bin/python -c 'import Cocoa; print Cocoa.NSEvent.modifierFlags() & Cocoa.NSControlKeyMask > 1'") is "True" end isControlKeyPressed To advance the page use: tell application id "sevs" control key down delay 0.2 control key up end tell Edited January 31, 2015 by dfay
HehMan Posted February 1, 2015 Posted February 1, 2015 dfay - Thanks so much for providing the detail. It was easy to implement and works perfectly. I look forward to enhancements to this work flow and additional features.
HehMan Posted February 5, 2015 Posted February 5, 2015 day - Is there a way to do a "Done" touch when dictation is complete? Or did I miss something in the above code? I hate to have to go to the mouse to complete the dictation.
HehMan Posted February 6, 2015 Posted February 6, 2015 (edited) I have entered the Apple Script exactly as dfay indicated in the first post. Dictation works perfectly. When I say "Press Return Key", a short message box (Press Return Key) appears above the dictation microphone and the cursor advances one line. I still must manually hit the Enter key to stop dictation. And yes, I have enabled dictation commands in System Preferences-Accessibiliry-Dictation Commands-Enable Advanced Commands. What am I missing? Edited February 6, 2015 by HehMan
dfay Posted February 6, 2015 Author Posted February 6, 2015 HehMan ... it's not entirely clear what you're trying to do. If you're in Alfred and say "Press Return Key", Alfred will behave as if you hit the key, by running the search / query / workflow in the input box. If you're in a text editor and say "Press Return Key", it will also behave as if you hit they key, by advancing the cursor one line. To stop dictation you can 1) use Alfred Remote and the same command above - it will toggle Dictation on or off depending on the state at the time it's run; or, 2) say "Stop Dictation" if you have Advanced Commands turned on as described above 3) press the function key twice Hope this helps.
HehMan Posted February 7, 2015 Posted February 7, 2015 dfay - "Stop Dictation" works perfectly. That was so simple. You are the master! Thank you.
gspot Posted April 16, 2016 Posted April 16, 2016 Having trouble getting this to work in El Capitan...does it need adjustment?
dfay Posted April 18, 2016 Author Posted April 18, 2016 No it's working fine for me....I recently did a clean reinstall of El Cap on my laptop and just tried using Alfred Remote to start Dictation for the first time & it worked immediately.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now