Jump to content

New line in path ...


Recommended Posts

I'm trying to get the current folder from Finder and then pass it to a bash script.

However the variable has a new line at the end.

How do I fix this?

 

(not sure how to show or attache workflow)

 

Apple script (osascript)

 

on run argv
    tell application "Finder"
        set currentFolder to (POSIX path of (folder of the front window as alias))
    end tell
end run

 

then I feed it to an "Args and Vars" -> debug -> script

 

debug is then showing the variable I assigned {query} from the apple script as containing a new line at the end of the path

 

for example

 

"/Applications/

"
 
instead of
"/Applications/"

 

 

Edited by mtissington
Link to comment

I think this is a bug introduced with the recent update - it was working correctly.

 

However I found that the following works and is probably more efficient

 

on run argv
    set bundleID to (system attribute "alfred_workflow_bundleid")

    tell application "Finder"
        set currentFolder to (POSIX path of (folder of the front window as alias))
    end tell

    tell application id "com.runningwithcrayons.Alfred"
            set configuration "path" to value currentFolder in workflow bundleID
    end tell
end run

Link to comment
3 hours ago, mtissington said:

I think this is a bug introduced with the recent update - it was working correctly.

 

It’s not a bug. AppleScript and JXA always return a new line at the end. You can avoid it by using the Objective-C bridge, but the Utility makes more sense.

 

3 hours ago, mtissington said:

the following works and is probably more efficient

 

Highly unlikely. AppleScript itself is slow. Plus, you’re setting a Workflow Environment Variable which affects the Workflow as a whole, which may or not come to bite you. Trimming the output is the cleanest and fastest way (depending on what your Workflow is doing).

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