Boek Posted March 29, 2018 Share Posted March 29, 2018 Hey all, new to Alfred, but I like it very much so far. here's the thing. i am building a workflow, which is supposed to paste a snippet in a file, where I typed the shortcode. I use a workflow because I want to add some variables, which should be pasted on several places in the snippet. One of the things I would like, is to paste the current filename in the snippet. Is that possible? Can anybody tell me how to do that, or point me to a topic where this was explained earlier? Many thanks in advance greets, Peter Link to comment
vitor Posted March 29, 2018 Share Posted March 29, 2018 Welcome @Boek, 1 hour ago, Boek said: current filename What do you mean by this? The current selected file in the Finder, a file selected in Alfred, a file open in an application? Link to comment
Boek Posted March 29, 2018 Author Share Posted March 29, 2018 I am triggering the workflow by snippetname, while working in a file. So I am in Atom, for example, editing an existing file. I trigger the workflow by typing !snippetname and I would like the have the name of the file I am working in available as a variable Link to comment
vitor Posted March 29, 2018 Share Posted March 29, 2018 (edited) In that case you’d need to find a way (via CLI) to have Atom return what file name is currently open. Edited March 30, 2018 by vitor Link to comment
deanishe Posted March 29, 2018 Share Posted March 29, 2018 What I did with Sublime is write a plugin (for Sublime) instead. It fires when you change tab, and if the current tab has a valid filepath, it writes it to ~/.sublime.current.txt. If there's no valid filepath, it deletes the file. Link to comment
GuiB Posted March 29, 2018 Share Posted March 29, 2018 You can also use AppleScript to find the title of the document like that: tell application "System Events" tell application process "Atom" to return title of first window end tell If you want to have a more general script that would work with other applications, you can get the window title of the front application like that: tell application "System Events" tell (first application process whose frontmost is true) to return title of first window end tell Regarding Atom, note that Atom would return a string that look like "fileName.extension — folderPath" so you can split the string into the fileName and folderPath if needed or get only one part if the other is not needed 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