shau-kote Posted April 11, 2016 Share Posted April 11, 2016 Hello. When I use Run Script in my workflows, working directory for script is the workflow directory. It is very convenient. But with NSApplescript working directory is / (root directory). It makes troubles for me. Is there a reliable way to get (into) workflow directory in NSApplescript? Yes, I can hard-code it, but (1) it's awfully long and (2) I'm not sure how Alfred generates its name (can it change in future? will it the same on the other installation?). Thanks for you replies. Link to comment
FroZen_X Posted April 11, 2016 Share Posted April 11, 2016 This Problem has been brought up before. Maybe this here helps you figuring out: http://www.alfredforum.com/topic/3391-find-workflow-folder-with-applescript/ Other than that you can run a little script that retrieves you the directory, which would be better but stil meh. Link to comment
shau-kote Posted April 29, 2016 Author Share Posted April 29, 2016 Thank for your reply, FroZen_X, but there is no new information in topic you adduced: yes, I can use Run Script instead of NSApplescript. Alack, I don't still see simple and tidy way to get into workflow folder using NSApplescript. Link to comment
deanishe Posted April 29, 2016 Share Posted April 29, 2016 I think you've missed the point, which is don't use Run NSAppleScript. FroZen_X 1 Link to comment
shau-kote Posted April 30, 2016 Author Share Posted April 30, 2016 Oh. Apparently I have. But I understood the same point while writing the first post. But my problem is: I want run NSAppleScript in workflow directory. Well, I will try another solutions. It is not a fatal problem, just a inconvenience. Link to comment
deanishe Posted May 1, 2016 Share Posted May 1, 2016 (edited) But my problem is: I want run NSAppleScript in workflow directory. Why? In what way is a normal Run Script Action with Language set to /usr/bin/osascript (AS) not acceptable? Especially considering that it does run in the workflow directory by default and is, by all appearances, exactly what you need. If you give me a reason why only an NSAppleScript will do, I'll tell you how to work out the workflow directory (I'm not going to explain it without a good reason because it's a very messy solution to a problem that is easily solved using a normal Run Script Action, and NSAppleScript is usually a bad choice, anyway.) Edited May 1, 2016 by deanishe Link to comment
shau-kote Posted May 1, 2016 Author Share Posted May 1, 2016 1. When I do display notification in NSAppleScript I see a notification with nice and meaningful Alfred icon but when I do the same in Run Script Action I see a notification with miserable and irrelevant AppleScript icon. 2. NSAppleScript cache compiled AS. It is not a notable optimization but it's better to do it than not to do. Here is my two reasons, but I do not think the reasons are sufficient to use "a very messy solution". There are another ways. Link to comment
deanishe Posted May 1, 2016 Share Posted May 1, 2016 Ah, notifications. Yeah, that's a good reason to use NSAppleScript. The caching/compilation can be achieved by saving your script in a .scpt file, too. The method I was thinking of to get a workflow's directory from a script (Alfred's environmental variables) actually doesn't work from NSAppleScript, 'cos there are no environmental vars Link to comment
shau-kote Posted May 1, 2016 Author Share Posted May 1, 2016 Yes, I was investigating the Alfred's environmental variables just now; unfortunately this method doesn't work. But the environmental variables seems very useful in Run Script Action. Thank you, deanishe, I've overlooked it. I know that *.applescript can be compiled by osacompile to *.scpt. But it is unnecessary headache to do it. Link to comment
deanishe Posted May 1, 2016 Share Posted May 1, 2016 (edited) FWIW, when Alfred's own notifications aren't good enough, most folks use terminal-notifier. You can set the icon you want, and you don't have the other limitations of NSAppleScript, most notably having to paste your code in the Script box (which is a pain, and messes with version control) and the fact that NSAppleScript runs on Alfred's main thread, blocking Alfred till it finishes. Edited May 1, 2016 by deanishe Link to comment
shau-kote Posted May 1, 2016 Author Share Posted May 1, 2016 Yes, I already know about terminal-notifier, thank for Vítor, who uses it in many of him workflows. terminal-notifier is fairly handy even though it doesn't seem to me like a tidy solution. Link to comment
deanishe Posted May 1, 2016 Share Posted May 1, 2016 No, I don't like the idea of terminal-notifier, either, but with the notifications API being so crappy, it's probably the best solution if you can't or don't want to use Alfred's Post Notification output. I do something similarly hacky in my own Python library to allow notifications. Link to comment
raguay.customct Posted May 2, 2016 Share Posted May 2, 2016 If you use JavaScript for Automation (JXA), you can use this to get environment variables: ObjC.import('stdlib');var alfver = $.getenv('alfred_version').split(".")[0];var alfapp = "Alfred " + alfver;var appAlfred = Application(alfapp);appAlfred.includeStandardAdditions = true;appAlfred.runTrigger("OpenDir", { inWorkflow: "com.customct.AlfredBrowser", withArgument: "{query}"}); It is run by oscascript with the "-l JavaScript" flag. This example get the Alfred version for knowing which Alfred to call and external trigger. Link to comment
shau-kote Posted May 4, 2016 Author Share Posted May 4, 2016 (edited) It is fascinating, but it is irrelevant for the topic answer in all senses. Edited May 4, 2016 by shau-kote deanishe 1 Link to comment
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