timmorrisdesign Posted October 2, 2014 Posted October 2, 2014 Hello, I have found a workflow that enables me to open my home folder in finder with a HotKey here: http://www.alfredforum.com/topic/855-how-to-open-a-folder-path-with-a-hotkey/ However, I want to be able to open whatever Microsoft Word document I am currently in, in Finder. Is there any keyword that opens the current path name that I can put into the text field in the Hotkey Settings? Thanks!
rice.shawn Posted October 2, 2014 Posted October 2, 2014 I'm confused. Do you mean that you want to open the directory that the current word document is in?
timmorrisdesign Posted October 2, 2014 Author Posted October 2, 2014 Sorry if that was unclear. Yes, I want to open the directory in Finder with a HotKey while in Microsoft Word.
rice.shawn Posted October 2, 2014 Posted October 2, 2014 This should work for you: https://www.dropbox.com/s/0s46hqcycya1ejc/Open%20MSWord%20Document%20Directory.alfredworkflow?dl=0 It'll just be up there temporarily.
timmorrisdesign Posted October 3, 2014 Author Posted October 3, 2014 Hi Shawn, Thanks a ton, unfortunately it isn't working. I set my hotkey and was in a Word document that has already been saved to a directory and then hit hit my hotkeys and nothing seems to be happening. Thoughts? Thanks, Tim
dfay Posted October 3, 2014 Posted October 3, 2014 I got this to work by changing the Run NSAppleScript to the less foolproof but working: on alfred_script(q) tell application "Microsoft Word" to set documentName to path of active document as alias tell application "Finder" to open the container of documentName end alfred_script the other code that I deleted from Shawn's version was checking if Word was active but in my testing it never returned True, so it never actually ran the two tell statements above. timmorrisdesign 1
rice.shawn Posted October 3, 2014 Posted October 3, 2014 (edited) It might be system dependent (I didn't really check that as much). I know that I got it to work on my machine. I got the actual string "Microsoft Word" by running an applescript from the script editor: delay 2 tell application "System Events" set frontApp to the name of the first application process whose frontmost is true return frontApp end tell For me, that returned "Microsoft Word"; if you run that same script, then it might be that the string returned is slightly different. Well, in that two seconds, I had to switch over to Word, but it worked then. You can get rid of this check and still have it be reliable by making the hotkey contextual to work only within Microsoft Word. To do this, double-click on the "hotkey" and press the "Related Apps" tab. Then add Microsoft Word. Another possibility is that it is opening the folder but not putting focus on it. Is that true? Edited October 3, 2014 by Shawn Rice timmorrisdesign 1
timmorrisdesign Posted October 3, 2014 Author Posted October 3, 2014 Hi Shawn, That is correct, it is opening it, but not putting focus on it, any way to change that? Also, I was hoping to have the file highlighted in that directory if possible. Thanks!
timmorrisdesign Posted October 3, 2014 Author Posted October 3, 2014 Ok, I figured it out to put focus on the directory I added and it works tell application "Finder" activate end tell
timmorrisdesign Posted October 3, 2014 Author Posted October 3, 2014 But any way to make the file selected within the directory?
rice.shawn Posted October 3, 2014 Posted October 3, 2014 Use this as the applescript: on alfred_script(q) tell application "System Events" set frontApp to the name of the first application process whose frontmost is true if (frontApp is "Microsoft Word") then set continueProcess to true else set continueProcess to false end if end tell if continueProcess then tell application "Microsoft Word" to set documentName to path of active document as alias tell application "Finder" open the container of documentName activate select documentName end tell end if end alfred_script There's probably a more efficient way to do this, but this way works. timmorrisdesign 1
timmorrisdesign Posted October 3, 2014 Author Posted October 3, 2014 One more quick request, I am realizing this would be really helpful to be able to do in Coda 2 as well. I tried this another if statement like this but it isn't doing anything with Coda. I put an "else if" statement in with Coda 2 and it still worked in Word, however when I replaced the bottom portion with Coda 2 it didn't work, not sure how I would leave the bottom portion to work with both Word and Coda 2 either. Thoughts? This is what I have right now just to see if I can get Coda 2 doing the exact same thing (open in finder and highlight the file in the directory). Thanks again! on alfred_script(q) tell application "System Events" set frontApp to the name of the first application process whose frontmost is true if (frontApp is "Microsoft Word") then set continueProcess to true else if (frontApp is "Coda 2") then set continueProcess to true else set continueProcess to false end if end tell if continueProcess then tell application "Coda 2" to set documentName to path of active document as alias tell application "Finder" open the container of documentName activate select documentName end tell end if end alfred_script
rice.shawn Posted October 3, 2014 Posted October 3, 2014 It's not going to work the same way with Coda 2 as it will with MS Word, primarily because "path of active document" is part of Word's AS Dictionary. I don't have Coda installed, so I can't really look up what they have or have not built. But, you can do this: open up "Script Editor," and then "File->Open Dictionary..." and see if Coda 2 has an AppleScript dictionary. If it does, it might have some properties that you could plug in to the script rather than the "path of active document."
timmorrisdesign Posted October 4, 2014 Author Posted October 4, 2014 (edited) I tried it out and Coda does have an Applescript dictionary. I tried it with the keywords from the ones listed in the Word one, but "active document" doesn't exist, here is a few of the words that might be in the same field but maybe they need to be presented differently, thoughts? local path: the local path of the site path: the path of the browser item file: Its location on the disk, if it has one. Also does "documentName" stay the same? Shawn, do you have a paypal email address, I would like to give you a little something for helping me out. You can email me your paypal email address to tim@timmorrisdesign.com if you would like. Edited October 4, 2014 by Tim Morris
rice.shawn Posted October 4, 2014 Posted October 4, 2014 documentName can stay the same because it's a variable rather than an AS property. It looks like local path refers to site, and path refers to the path of a browser item -- neither of which are the current document that you're editing. So, try something like: tell application "Coda 2" to set documentName to file of document 1 as alias That may or may not work. To debug it a bit, try just opening Script Editor and popping in that single line of code and see what happens (make sure Coda is open at the time).
timmorrisdesign Posted October 5, 2014 Author Posted October 5, 2014 Thanks! I added another if/else if statement below to get it to work correctly with your last snippet. My final code that worked is: on alfred_script(q) tell application "System Events" set frontApp to the name of the first application process whose frontmost is true if (frontApp is "Microsoft Word") then set continueProcess to true else if (frontApp is "Coda 2") then set continueProcess to true else set continueProcess to false end if end tell if continueProcess then if (frontApp is "Microsoft Word") then tell application "Microsoft Word" to set documentName to path of active document as alias else if (frontApp is "Coda 2") then tell application "Coda 2" to set documentName to file of document 1 as alias end if tell application "Finder" open the container of documentName activate select documentName end tell end if end alfred_script
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