Jump to content

applescript behaves differently in Alfred


Recommended Posts

Posted

I've got an applescript which opens a specific path in the finder. When implementing this applescript in Alfred it behaves different. 

for instance, setting "q" to "~" (the home directory) will open the folder in the finder. 

But passing "~" in alfred in my workflow as an argument will reveal the folder, not open the folder.

I want it to open the folder, similar to how the go to function in Finder works. Not reveal it. 

In Alfred I am using the Run NSAppleScript action and a keyword with an argument to trigger the script. 

set q to "~"

set folder_var to true

set mypath to q as text

if mypath = "~" then
	set q to "/Users/David"
else if "~" is the first character of mypath then
	set mytext to text 2 thru (count of mypath) of mypath
	set q to "/Users/David" & mytext
end if


set q to (POSIX file q) as alias

if kind of (info for q without size) is not "Ordner" then
	set folder_var to false
end if





if folder_var is true then
	if mypath = "~" then
		set q to "/Users/David"
		set q to (POSIX file q) as alias
	end if
	tell application "Finder"
		activate
		make new Finder window to folder q
	end tell
else
	tell application "Finder"
		activate
		reveal q
	end tell
end if

 

Posted

Try a normal Run Script action with Language = /usr/bin/osascript (AS) instead.

 

You shouldn't use Run NSAppleScript unless you have a very good reason to.

Posted

Thanks for all the input, so far, the behavior has not changed.

It reveals the folder instead of going into it. But running the exact same script (without the "on alfred_script (q)" part) makes the Finder go into the folder. 

The script should go into the folder, but reveal if the given argument is a file.

 

Posted
3 minutes ago, deanishe said:

Bit of a long shot, but it may be due to Alfred being English. 

 

It appears that your script checks whether the type is "Ordner". Have you tried using "Folder" in Alfred?

 

Yep that was it. Thanks a lot. Solved my problem!

Posted

Here's a better way that works regardless of system language:

 

on isFolder(theAlias)

    return folder of (info for theAlias without size)

end isFolder

 

That gives you a simple true/false.

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