Jump to content
WalterBeiter

applescript behaves differently in Alfred

Recommended Posts

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

 

Share this post


Link to post

How are you running the script? In Script Editor? With osascript? With a Run Script action? With a Run NSAppleScript action?

Share this post


Link to post

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.

Share this post


Link to post

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.

 

Share this post


Link to post

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?

Share this post


Link to post
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!

Share this post


Link to post

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.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...