Jump to content

Go To Path in Open/Save Dialogue


Recommended Posts

Hey,

 

I've been trying to convert this launchbar script into an Alfred Workflow. The script is meant to take the current selection of Alfred, and activate the window behind, open the "Go To Folder" dialogue, paste in the path and press enter. 

 

I got it working in the AppleScript Editor, but for some reason I can't get it to perform on through Alfred. It even opens up the "Go To Folder" dialogue but stops there each time. Do you guys have any ideas?

 

 

on alfred_script(q)
	
	set filePath to POSIX file of q
	
	tell application "System Events"
		set theApplication to application processes whose frontmost is true
		set target to item 1 of theApplication
		set target to a reference to front window of target
		set target to a reference to front sheet of target
		delay 0.5
		tell target to keystroke "g" using {command down, shift down} -- Activate goto field
		tell target
			try
				set value of text field 1 to filePath
				delay 0.5
				key code 36 -- simulate pressing the Enter key
			end try
		end tell
	end tell
	
end alfred_script

 

 

 
Link to comment

OK. I made a workflow and tested it only with AppleScript Editor. Here is the code that worked:

 

—-The save as dialog uses text as input and UNIX path as far as I can tell
set filePath to POSIX path of q as text

tell application "System Events"
	set theApplication to application processes whose frontmost is true
	set target to item 1 of theApplication
	set target to a reference to front window of target
	set target to a reference to front sheet of target
	delay 0.5
	tell target to keystroke "g" using {command down, shift down} -- Activate goto field
	delay 0.5
	tell target
		set value of text field 1 to filePath
		delay 0.5
		key code 36 -- simulate pressing the Enter key
	end tell
end tell

 

I removed the “try” part of the code to better debug it… Your final code of course may add them back.

 

Finally, you can write AppleScript directly using Language "/usr/bin/osascript”.

Edited by Carlos-Sz
Link to comment
  • 2 months later...

Was anyone able to make a working workflow they could share? I've been scratching my head trying to get the correct combination of events.

 

Just wondering, is it possible to drill down to a location using Alfred's system browser then change the location in the dialog box?

 

Thanks

Edited by ZeroFill
Link to comment

Was anyone able to make a working workflow they could share? I've been scratching my head trying to get the correct combination of events.

 

Just wondering, is it possible to drill down to a location using Alfred's system browser then change the location in the dialog box?

 

Thanks

 

I’ve added similar feature but with a different approach in two of my workflows (the first one is also a feature in the second one):

 

Default Folder

 

Recent Finder Items

Link to comment
  • 3 years later...

Was anyone able to make a working workflow they could share? I've been scratching my head trying to get the correct combination of events.

 

Just wondering, is it possible to drill down to a location using Alfred's system browser then change the location in the dialog box?

 

Thanks

 

@Carlos-Sz : Nice work! Good demonstration of many ways with which this can be done with Alfred.

 

@<others> :)

 

I know its an old thread. But I also came here looking for this and I believe so will others. A simple File Action is what is called for.

I possess no special workflow skills, but still, I am posting the solution for those who cannot create this workflow:

 

https://www.dropbox.com/s/55534rd0c5wpxhl/open_save_dialog.alfredworkflow?dl=0

 

How to use?

Bring up any file/folder in Alfred

type your shortuct for action Action

and run this workflow which is currently named "Send To Open or Save dialog".

 

I personally believe (and I have nothing against what anyone else's approach is):

1. Alfred's File Search is neatly organised.

2. Single quote easily gets me to the folder/file I need to.

3. There is no need to over-complicate things by adding new keywords and then performing actions to get to the item which you could have easily got to by typing single quote in the first place. The more the keywords, the more the complications (naming pattern, length etc) in using them.

4. When 2 shall not remain true, then and only then, create Favorites folder, otherwise you are slowing yourself down instead of doing things quickly.

 

 

Thanks.

Edited by rounak
Link to comment
  • 8 months later...
On 9/5/2016 at 0:08 AM, rounak said:

 

@Carlos-Sz : Nice work! Good demonstration of many ways with which this can be done with Alfred.

 

@<others> :)

 

I know its an old thread. But I also came here looking for this and I believe so will others. A simple File Action is what is called for.

I possess no special workflow skills, but still, I am posting the solution for those who cannot create this workflow:

 

https://www.dropbox.com/s/55534rd0c5wpxhl/open_save_dialog.alfredworkflow?dl=0

 

How to use?

Bring up any file/folder in Alfred

type your shortuct for action Action

and run this workflow which is currently named "Send To Open or Save dialog".

 

I personally believe (and I have nothing against what anyone else's approach is):

1. Alfred's File Search is neatly organised.

2. Single quote easily gets me to the folder/file I need to.

3. There is no need to over-complicate things by adding new keywords and then performing actions to get to the item which you could have easily got to by typing single quote in the first place. The more the keywords, the more the complications (naming pattern, length etc) in using them.

4. When 2 shall not remain true, then and only then, create Favorites folder, otherwise you are slowing yourself down instead of doing things quickly.

 

 

Thanks.

Any chance of a fix to the DropBox link?

 

Link to comment
  • 1 year later...

Hello dreamers.

For anyone coming here still looking for this, so was I, and I managed to create something which does exactly what I want.

 

Here it is:

https://drive.google.com/file/d/1NQyB4u58QWxC8BR-9VgBmy2MEioGuQ2m/view?usp=sharing

 

It has two triggers. 

Either you search for a file the normal way (pressing space), then action it and pick "Paste path into dialog box"

or

You start a custom file search using "p", then just press enter when you've found your file/folder and voila.

 

Hope this helps someone!

 

Love

Paul

 

makesmefeel.com

Edited by oldflattop
Link to comment
  • 1 year later...
  • 2 years later...
  • 3 months later...

This broke for me on Monterey too, but I managed to fix it by swapping out the RunNSAppleScript action for a plain RunScript action, and making very slight tweaks to the script just because the way the query is passed in is very slightly different.

 

At least... I'm not much of a coder, but it seems to be working for me... 

 

on run argv
  set theQuery to item 1 of argv
tell application "Finder" to set the clipboard to theQuery as text

tell application "System Events"
    set theApplication to application processes whose frontmost is true
    set target to item 1 of theApplication
    set target to a reference to front window of target
    set target to a reference to front sheet of target
    delay 0.5
    tell target to keystroke "g" using {command down, shift down} -- Activate goto field
    delay 0.2
    tell target
        delay 0.2
		tell application "System Events" to keystroke "v" using {command down}
        -- simulate pressing the Enter key
key code 36
    end tell
end tell

return theQuery
end run

 

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...