Jump to content

New to scripting - shell script issue?


Recommended Posts

I'm new to Alfred and scripting and I'm having a problem.

 

I have Alfred 2 w/ Powerpack and I'm trying to run several workflows that aren't working.  A small number are working. What seems to be a common thread in the workflows that will not work correctly is they use "/bin/bash/" as the language option (shell script - correct?) within the workflow.   I have at least one that uses a script written in ruby that works fine (Append to Journal workflow).

 

I am trying to get a workflow up and running that will allow me to prepend notes to a scratchpad/journal file (.txt) in nvAlt.  There are numerous workflows available to do this but none functions correctly for me (although the workflow provided by Agile Tortoise to APPEND to a file works fine - it is the one I mention above that uses a script written in ruby).

 

I have tried to troubleshoot as best as I can but I'm basically stumbling around in the dark.  I have checked my Python configuration (was v 2.7.2, now upgraded to 2.7.4) since I have seen references to that being a potential issue.  I have uninstalled Alfred 2 and reinstalled since updating Python.  I have checked and repaired my permissions (using Onyx).  I'm not sure what to do next and I'm hoping someone might help...

 

I have tried the following workflows without success (and several others as well):

 

- nvAlt Tag Search for Alfred 2 ( http://brettterpstra.com/2013/03/17/nvalt-tag-search-for-alfred-2/

 

- Quick Jot Workflow - ( http://www.alfredforum.com/topic/2175-quick-jot-workflow-collect-timestamped-stacking-jots-in-a-single-text-file/ )

 

 

The one I would prefer to get running is "Notes" by Mark Sternfels ( http://asmodified.net/alfredworkflows/ ) since it allows saving to several different running textiles.  I've been searching these forums for the last two days trying out various options that seem like possibilities but nothing has solved the problem.

 

Anyone have the time to lend a hand?

 

I'm running:

 

- Mountain Lion 10.8.3

- Alfred 2.0.3

- Python 2.7.4

- nvAlt 2.2b

 

Thanks!

Link to comment

I don't know why your having problems but you need to give the more knowledgable folks around here something more to work with. Do you get any error when running the scripts from the command line that could be useful? I do know that the ~/library/application support/notational data/ folder are marked system files and in alfred's file filter -> search scope (second tab) -> show files marked as system file if your searching for notes etc... I had that problem at first so thank David Ferguson if that helps solve at least a couple problems as  I couldn't figure it out to save my life.

 

It seems you have a newer version of python installed from homebrew I am gathering... did you update your path to prepend /usr/local/bin and the python path's that are necessary /usr/local/share/python 

 

 

REally stretching here so give some info please.

Link to comment

I'm new to Alfred and scripting and I'm having a problem.

 

I have Alfred 2 w/ Powerpack and I'm trying to run several workflows that aren't working.  A small number are working. What seems to be a common thread in the workflows that will not work correctly is they use "/bin/bash/" as the language option (shell script - correct?) within the workflow.   I have at least one that uses a script written in ruby that works fine (Append to Journal workflow).

 

I am trying to get a workflow up and running that will allow me to prepend notes to a scratchpad/journal file (.txt) in nvAlt.  There are numerous workflows available to do this but none functions correctly for me (although the workflow provided by Agile Tortoise to APPEND to a file works fine - it is the one I mention above that uses a script written in ruby).

 

I have tried to troubleshoot as best as I can but I'm basically stumbling around in the dark.  I have checked my Python configuration (was v 2.7.2, now upgraded to 2.7.4) since I have seen references to that being a potential issue.  I have uninstalled Alfred 2 and reinstalled since updating Python.  I have checked and repaired my permissions (using Onyx).  I'm not sure what to do next and I'm hoping someone might help...

 

I have tried the following workflows without success (and several others as well):

 

- nvAlt Tag Search for Alfred 2 ( http://brettterpstra.com/2013/03/17/nvalt-tag-search-for-alfred-2/

 

- Quick Jot Workflow - ( http://www.alfredforum.com/topic/2175-quick-jot-workflow-collect-timestamped-stacking-jots-in-a-single-text-file/ )

 

 

The one I would prefer to get running is "Notes" by Mark Sternfels ( http://asmodified.net/alfredworkflows/ ) since it allows saving to several different running textiles.  I've been searching these forums for the last two days trying out various options that seem like possibilities but nothing has solved the problem.

 

Anyone have the time to lend a hand?

 

I'm running:

 

- Mountain Lion 10.8.3

- Alfred 2.0.3

- Python 2.7.4

- nvAlt 2.2b

 

Thanks!

 

In cases like this where it seems to be a lot of things going on (or not) I've found that it's better to start with something basic and see if that works and then go from there. So, with that being said, let's try something. If you believe that the common thread is that workflows that use /bin/bash are working, let's create a basic workflow that uses bash and see if we can get output from it.

 

Could you...

1. Open Alfred Preferences to the Worfklows area

2. Click the + in the bottom right of the list area and select Templates->Essentials->Keyword to Script to Notification.

3. In the newly created workflow, double click the Keyword item, and set a keyword with a descriptive title and subtext. For this example, set the keyword to accept No Argument. Save.

4. Double click the Run Script item. Leave the language as /bin/bash and set the script to do something simple like...

currdate=$(date +"%c")
echo $currdate

 

       then save.

5. Double click the Post Notification item, set the Title to "Date" and the Text to {query}, then save.

 

At this point, your workflow is set up and ready to go. Using the keyword you specified will save the current date into the currdate variable and then echo that, which outputs to an OSX Notification.

 

Can you test this and tell me if you get the expected notification as a result?

Link to comment

In cases like this where it seems to be a lot of things going on (or not) I've found that it's better to start with something basic and see if that works and then go from there. So, with that being said, let's try something. If you believe that the common thread is that workflows that use /bin/bash are working, let's create a basic workflow that uses bash and see if we can get output from it.

 

Could you...

1. Open Alfred Preferences to the Worfklows area

2. Click the + in the bottom right of the list area and select Templates->Essentials->Keyword to Script to Notification.

3. In the newly created workflow, double click the Keyword item, and set a keyword with a descriptive title and subtext. For this example, set the keyword to accept No Argument. Save.

4. Double click the Run Script item. Leave the language as /bin/bash and set the script to do something simple like...

currdate=$(date +"%c")
echo $currdate

 

       then save.

5. Double click the Post Notification item, set the Title to "Date" and the Text to {query}, then save.

 

At this point, your workflow is set up and ready to go. Using the keyword you specified will save the current date into the currdate variable and then echo that, which outputs to an OSX Notification.

 

Can you test this and tell me if you get the expected notification as a result?

I followed your directions and received a notification through ML saying "  "Date"  " in my system notifications.

 

Thanks for your help!

Link to comment

I followed your directions and received a notification through ML saying "  "Date"  " in my system notifications.

 

Thanks for your help!

 

But did it say anything other than "Date"? Date was just the title. Did it not show a string version of the date as well?

Link to comment

 Screengrab of result is here:  https://www.dropbox.com/s/jfiou1yxi4w12yy/Alfred%20Script%20Result%201.jpg

 

Contents of Workflow script are shown here:

 

https://www.dropbox.com/s/pjnzj6rs44ni9lr/Alfred%20Script.jpg

 

Thanks for your help!

 

So, based off this, this proves that there is nothing wrong with /bin/bash, it works perfectly.

 

Also, it's worth noting that, the workflow that you mentioned that you would like to use... I'm not sure how much you looked into it.. I'm assuming not much if you're new to scripting but, one thing the author of the workflow didn't take into account was to check whether or not a specific folder existed. His works with multiple files and saves them all in ~/Dropbox/Notes. The workflow doesn't check to see if ~/Dropbox/Notes exists, it just assumes it does. Ever heard the old expression about what assuming does? :) If that folder doesn't exist, the workflow quietly fails. As a quick and easy test, could you create that folder and try that workflow again and see if it does work?

Link to comment

So, based off this, this proves that there is nothing wrong with /bin/bash, it works perfectly.

 

Also, it's worth noting that, the workflow that you mentioned that you would like to use... I'm not sure how much you looked into it.. I'm assuming not much if you're new to scripting but, one thing the author of the workflow didn't take into account was to check whether or not a specific folder existed. His works with multiple files and saves them all in ~/Dropbox/Notes. The workflow doesn't check to see if ~/Dropbox/Notes exists, it just assumes it does. Ever heard the old expression about what assuming does? :) If that folder doesn't exist, the workflow quietly fails. As a quick and easy test, could you create that folder and try that workflow again and see if it does work?

 

I really appreciate your help - another question if you don't mind since it still is not working.  

 

I did reset the locations specified in the script to my actual folders and actual filenames.  Is it possible that characters and/or spaces used in my file and folder names are throwing things off?  I use dashes ( - ) in some of my names as well as spaces between words.  I have also used colons in a few.  Could that be throwing things off, because these workflows/scripts are still not working for me?

 

Here's an example of one I'm trying to get working in the "Notes" workflow by Mark Sternfels:

 

 

 

echo -e "--- "`date +'%Y.%m.%d %H:%M:%S'`" ---\n" {query} "\n"> /tmp/notetmp




cat ~/Dropbox/Scott Dropbox/1-Working Folder/Notes/Grocery List.txt >> /tmp/notetmp


cp /tmp/notetmp ~/Dropbox/Scott Dropbox/1-Working Folder/Notes/Grocery List.txt


rm /tmp/notetmp

 

 

 
The file and folder specified both exist and are names as shown in the script.  Any ideas?

 

 

Thanks so much for taking the time to lend me a hand! 

Link to comment

Added note:  I reinstalled then ran the workflow using the "as written" script, location and filename by making files/folders to match and it worked fine.  When I change it back to where my actual folders and files are it stops working.  

 

Seems like it's something to do with the folder/file names.

 

Another thought - some of my folders within Dropbox are Symbolic links (but not the folder containing my nvAlt notes) - could this be part of the problem?

Link to comment

New update:

 

It has something to do with using spaced in the folder names.  I rebuilt new folders and paths that used dashes, colons and other characters and they all work fine.  However, when a folder is added that has multiple words in the name separated by a blank space the workflow stops functioning!  The same is true for spaces in file names.

 

 

Any ideas?

Edited by grendel2000
Link to comment

Added note:  I reinstalled then ran the workflow using the "as written" script, location and filename by making files/folders to match and it worked fine.  When I change it back to where my actual folders and files are it stops working.  

 

Seems like it's something to do with the folder/file names.

 

Another thought - some of my folders within Dropbox are Symbolic links (but not the folder containing my nvAlt notes) - could this be part of the problem?

 

Spaces will most certainly throw it off. They would either need to be escaped or put quotes around the path. So using your example... for escaping...

echo -e "--- "`date +'%Y.%m.%d %H:%M:%S'`" ---\n" {query} "\n"> /tmp/notetmp
cat ~/Dropbox/Scott\ Dropbox/1-Working\ Folder/Notes/Grocery\ List.txt >> /tmp/notetmp
cp /tmp/notetmp ~/Dropbox/Scott\ Dropbox/1-Working\ Folder/Notes/Grocery\ List.txt
rm /tmp/notetmp

 

Notice the additional \'s to escape the spaces. If you would prefer to use quotes:

echo -e "--- "`date +'%Y.%m.%d %H:%M:%S'`" ---\n" {query} "\n"> /tmp/notetmp
cat "~/Dropbox/Scott Dropbox/1-Working Folder/Notes/Grocery List.txt" >> /tmp/notetmp
cp /tmp/notetmp "~/Dropbox/Scott Dropbox/1-Working Folder/Notes/Grocery List.txt"
rm /tmp/notetmp

 

That should get you going

Link to comment

FIXED IT!  

 

Spaces will most certainly throw it off. They would either need to be escaped or put quotes around the path. So using your example... for escaping...

echo -e "--- "`date +'%Y.%m.%d %H:%M:%S'`" ---\n" {query} "\n"> /tmp/notetmp
cat ~/Dropbox/Scott\ Dropbox/1-Working\ Folder/Notes/Grocery\ List.txt >> /tmp/notetmp
cp /tmp/notetmp ~/Dropbox/Scott\ Dropbox/1-Working\ Folder/Notes/Grocery\ List.txt
rm /tmp/notetmp

 

Notice the additional \'s to escape the spaces. If you would prefer to use quotes:

echo -e "--- "`date +'%Y.%m.%d %H:%M:%S'`" ---\n" {query} "\n"> /tmp/notetmp
cat "~/Dropbox/Scott Dropbox/1-Working Folder/Notes/Grocery List.txt" >> /tmp/notetmp
cp /tmp/notetmp "~/Dropbox/Scott Dropbox/1-Working Folder/Notes/Grocery List.txt"
rm /tmp/notetmp

 

That should get you going

Fantastic!  Thank you SO MUCH David!

Link to comment

Spaces will most certainly throw it off. They would either need to be escaped or put quotes around the path. So using your example... for escaping...

echo -e "--- "`date +'%Y.%m.%d %H:%M:%S'`" ---\n" {query} "\n"> /tmp/notetmp
cat ~/Dropbox/Scott\ Dropbox/1-Working\ Folder/Notes/Grocery\ List.txt >> /tmp/notetmp
cp /tmp/notetmp ~/Dropbox/Scott\ Dropbox/1-Working\ Folder/Notes/Grocery\ List.txt
rm /tmp/notetmp

 

Notice the additional \'s to escape the spaces. If you would prefer to use quotes:

echo -e "--- "`date +'%Y.%m.%d %H:%M:%S'`" ---\n" {query} "\n"> /tmp/notetmp
cat "~/Dropbox/Scott Dropbox/1-Working Folder/Notes/Grocery List.txt" >> /tmp/notetmp
cp /tmp/notetmp "~/Dropbox/Scott Dropbox/1-Working Folder/Notes/Grocery List.txt"
rm /tmp/notetmp

 

That should get you going

 

Actually, strangely, the version using quotes would have been my preferred "fix" but isn't working.  The version using the slashes works perfectly however.  Are there any other "gotchas" about characters you can or cannot use?  I tend to use colons and dashes in many of mu folder and file names - is there anything I should be aware of when using these?

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