Jump to content

Get filename of current file in workflowvariable


Recommended Posts

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...