MEs Posted August 30, 2016 Posted August 30, 2016 (edited) Hi, After using a few workflow downloaded here and on Packal (Google Translate, OS X Toolbox, Call or SMS contact for example), I have been creating some workflow of my own like a file filter and now to launch my apps, files and drives when I get to work. MOUNTING PART This part works, including a Run NSAppleScript to mount 2 volumes. Here it is : tell application "Finder" mount volume "smb://name-pc/Folder A" mount volume "smb://name-pc/FolderB" end tell As you can see, the first shared folder has a space in its name. But for mounting, it didn't seem to be a problem to mount them. But, I am always getting the pop-up window asking for username & password. Both of them are already written (and the "Remember in Keychain"is selected..) so all I have to do is click OK. I was wondering if there is a way to avoid this pop-up ? I for example used a simple shortcut prior to using Alfred and when clicking it, I didn't get the pop-up, which sounds logic since it is stored in my keychain. If not, how can I make Alfred to click OK for me ? UNMOUNTING PART Unfortunately, unmounting is not working by juste changing mount to unmount. So I found another way as written here : do shell script "umount /Volumes/Folder A" do shell script "umount /Volumes/FolderB" But Folder A is not unmounted... I even found an existing workflow in this board (here) but the unmount function of is also not capable of un mounting this particular folder. But it shows up when I type "unmount" keyword as "Folder%20A" So I tried those commands in my NSAppleScript : do shell script "umount /Volumes/Folder%20A/" do shell script "umount /Volumes/Folder\ A/" None of these made it unmount. But this one works in my mac Terminal : umount /Volumes/Folder\ A So I tried to add a Terminal Command action, but this one opens up the terminal when done. Is there a way to do it without getting the terminal app to actually launch ? If not, any idea on the correct syntax for the AppleScript command here ? Regards Edited September 3, 2016 by MEs
deanishe Posted August 30, 2016 Posted August 30, 2016 Yes. Just use a Run Script Action with Language = /bin/bash It's generally a better idea to also use Run Script Actions to run AppleScript, too, by setting Language = /usr/bin/osascript (AS) The reason is that Run NSAppleScript runs the script on Alfred's main thread, which blocks Alfred till the script finishes. The normal Run Script action runs in the background, so you can keep using Alfred. However, because AppleScript is weird, sometimes one will work but the other won't. MEs 1
MEs Posted August 31, 2016 Author Posted August 31, 2016 (edited) Hi, Thank you for your help. It works perfectly using /bin/bash indeed. On the mounting part, any idea how I can automatically say Connect for the credential pop-up to mount the shared folders ? Since Alfred 3.1 is out, I thought Key Combo would do the job, but it isn't. I placed the key combo "Return" after the NSAppelScript that mount the shared volume. Unfortunately, it is like it doesn't type Enter. Maybe I haven't understood the Key Combo use properly. Is there any other way to simulate an "Enter" keystroke or a click on the Connect button ? I guessed here using NSAppeScript is a better option, so the workflow will wait for the click or keystroke to be done before the other actions in the workflow and therefore won't loose the focus on the pop-up window. Correct me if this is not the best use. FYI I tried these so far in my AppleScript, none worked out : tell application "System Events" click button "Connect" end tell tell application "Finder" click button "Connect" end tell tell application "Finder" keystroke return end tell Regards Edited August 31, 2016 by MEs
deanishe Posted August 31, 2016 Posted August 31, 2016 (edited) To simulate pressing return, use: tell application "System Events" to key code 36 I don't know about any of the other stuff because I don't have any remote volumes. Edited August 31, 2016 by deanishe MEs 1
MEs Posted August 31, 2016 Author Posted August 31, 2016 I tried to add it in the same NSAppleScript but it didn't work It kinda worked by using an open /bin/bash command to mount the shared volumes & a /usr/bin/osascript for the code you mentioned. BIN/BASH open "smb://nef01-pc/ScanNEF01" OSASCRIPT tell application "System Events" to key code 36 To have them both mounted, I have to put the first Script mounting a drive followed by the osascript to tape Return, then the Script to mount the 2nd volume and again the script for key code 36. Sometimes it doesn't work, depends on how long it takes for the Pop Up to show up. Adding a delay in between didn't help. The downside is that I used the "open" bash function, which actually opens finder windows of each volumes mounted. All considered, not a much better result here. And I couldn't find any other command that could mount the volume using /bin/bash Language. I will keep trying until I figure something that works actually every time
deanishe Posted August 31, 2016 Posted August 31, 2016 And I couldn't find any other command that could mount the volume using /bin/bash Language. http://apple.stackexchange.com/a/698 MEs 1
MEs Posted September 3, 2016 Author Posted September 3, 2016 Hi, Thank you for the link. In fact I already stumbled on it while looking for some answers, since there are not that many messages on forums speaking of this specific idea to use terminal command in this matter after 2013. Not sure why... So using the mount_smbfs function wasn't a solution by itself, since I didn't have the right to write on the /Volumes mountpoint. I finally tried to change the chmod of /Volumes to 777 even if it's not a perfect solution. Do it at your own risk if you need to. My final /bin/bash has been as following : mkdir /Volumes/Folder\ A mount_smbfs -N //user:password@server/Folder%20A /Volumes/Folder%20A To add some explanation if someone wants to use it, the -N option is used to avoid the Connect op-up window. The mkdir function will create a folder, that will be replaced by the volumes as soon as it's mounted. When unmounted, the folder will not be there anymore. Which is why you need to keep the mkdir line. If the shared folder you need to mount has a space in it's name, you will need to add a \ before the space in the mkdir function and replace by %20 in the mount_smbfs function. If you have multiple folder to add, juste repeat those 2 lines, replacing the informations as needed. This is the only way I could come up with so far to have a real workflow working, because after this script, I added a few applications to launch, 2 files as well and a script to hide the app after they are opened, and a few tabs to open in my work navigator. By the way, the code to hide an app as a NSAppleScript : tell application "System Events" to tell process "Microsoft Excel" to set visible to false Thanks again for your help deanishe
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