Jump to content

Bash script will not work. Unable to create new variable from "awk" statement. But it works in the shell!


Recommended Posts

Hi.

 

I was wondering if anyone could help with the following bash script? It is supposed to do the following:

 

  1. You copy the URL of an outlook365 email.
  2. You call the workflow in Alfred
  3. It manipulates the copied URL and pastes this in your active app
  4. The link can now be clicked to take you to the email.

 

NB sadly this only works when conversation view is turned off.

 

I am having trouble capturing the output of the "awk" command. This is used to identify the ID of the email (the letters after the last forward slash). I've checked this on the command line, and it works fine. But it doesn't seem to work within Alfred. I think it might be to do with the use of "echo". That seemed to be the only way to capture the output of the "awk" command.

 

The code is below, and you can try out the following URL "https://outlook.office.com/mail/inbox/id/AAMkAGYxY2E3NTk1LTE4MWEtNGM5OS05mZkLTMzZTA3YjE1ZWIzMQBGAAAAAACvq4d8nTSiTKyFrc7qQPbCBwCPfjnaKUWETJ10gdKjawcfAF5453XCAADypvc4SG%2BZQpfh%2FKsqPMSCAUqTI5OAAA%3D" (NB it won't actually take you to the email because you need to be logged on as me!)

 

Any pointers welcome!

 

# Get last item in clipboard

query="{clipboard:0}"

# Extract email id

id=$(echo $query | awk -F "\/" '{print $NF}' )

# Create URL

string1="https://outlook.office.com/owa/?ItemID="
string2="&viewmodel=ReadMessageItem&path=&exvsurl=1"

url="$string1$id$string2"

# paste

echo -n $url

 

Link to post

Hi @nick_r, welcome to the forum.

 

It's likely due to the configuration of your shell environment (which Alfred doesn't use).

 

There's a bunch of other things it could be, but of course we can't say for sure without the workflow.

Link to post

Thanks for the rapid response. I see that I am not able to attach workflow (presumably for security reasons?), but the it's quite simple:

 

The first module is a "Keyword" without an argument.

The second module is the bash script which takes its arguments from the clipboard.

The final module is "Copy to Clipboard" module which uses plain text, has the content {var:id}, automatically pastes to the frontmost app, and makes the clipboard item transient.

 

I've provided screenshoots of the overall workflow, and the final module.

 

Is this information sufficient?

 

It still seems to be the case that the line with the awk command is malfunctioning even though it works fine in the shell. I've noticed that you can change the scripting language, and I've changed it to zsh which is the scripting language for the terminal, but it still keeps making this error. I think perhaps the best approach would be to rewrite this in python, which probably has better string manipulation?

 

(NB realise these are newbie questions - this is my first workflow)

 

Thanks

N

alfred1.png

alfred2.png

Link to post
11 hours ago, nick_r said:

Is this information sufficient?

 

No, sorry. Please upload the workflow somewhere (Dropbox?) and post a link. It's important that we're talking about exactly the same workflow.

Link to post

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