Page 1 of 1

Terminal Paste File Name Only

PostPosted: Mon Jan 02, 2017 12:44 pm
by Plex
Hello,

I'm using Hazel to identify an .RTF file with a specific name and then I want to paste just that file's name without the extension (but not actual path) into the terminal.

Here's where I've gotten so far with the shell script, except I get an error in the logs:

Code: Select all
filename=$(basename "$1")

filename=${filename%.*}

server="https://www.server.com/"

hash="$server$filename"

/usr/bin/app "$hash"


What I want it to output is:

Code: Select all
/usr/bin/app https://server.com/filename


I've also tried this and get an error as well:

Code: Select all
LONG_FILENAME="$1"

VARIABLE=$(basename "$LONG_FILENAME")

server="https://www.server.com/"

hash="$server$filename"

hash="$server$VARIABLE"


Does anyone have any suggestions? I'm wondering if the "$1" needs to appear somewhere in the terminal's action?
If I could see the actual terminal output, that might help diagnose the problem, too. Is that possible to get it to run in a visible terminal?

Thanks!

Re: Terminal Paste File Name Only

PostPosted: Mon Jan 02, 2017 12:46 pm
by Mr_Noodle
Does it run ok outside of Hazel?

To see the script output in Hazel's logs, turn on debug mode as described here: https://www.noodlesoft.com/kb/hazel-debug-mode/

Re: Terminal Paste File Name Only

PostPosted: Mon Jan 02, 2017 1:05 pm
by Plex
Thanks for the debug idea (tip)! It's working, looks like it was a simple syntax issue. Thank you.

As an aside, I'm not sure how to run it outside of Hazel, actually, as I'm not modifying the file itself, just using it's name in a command.