Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Permission Denied when running ruby scripts?

edited March 2013 in FastScripts

I've just started playing around with FastScripts and haven't been able to find anything that relates to my question on the forum.

When I run certain ruby scripts I get permission denied errors if that script does any file read/write operations or any other system or exec bash commands.

For example, I have a script that pulls JSON and parses it. It then creates a tab-separated file and opens the file in excel.

storage = Crack::JSON.parse(RestClient.get(url))

storage.each do |x|
name = x["customer_name"]
value = x["value"]

content = "#{name}\t#{value}\n"
target = "foo.tsv", "a") do |f|

system ("open foo.tsv")

When I run this script from FS I get the following error:

/Users/spayne/.../.../.../scripts/foobar.rb:22:in `initialize': Permission denied - foo.tsv (Errno::EACCES)
from /Users/spayne/.../.../.../scripts/foobar.rb:22:in `open'
from /Users/spayne/.../.../.../scripts/foobar.rb:22
from /Users/spayne/.../.../.../foobar.rb:15:in `each'
from /Users/spayne/.../.../.../scripts/foobar.rb:15


The script runs perfectly from the command line. What permissions do I need to set to launch this script with FS?




  • Hi Seth - I haven't done any scripting myself with Ruby, but I'm happy to look into this. Do you think you could come up with a minimal example script that exhibits the problem but doesn't rely on e.g. any of your URLs/etc? Is it as simple as just creating a ruby script that tries to write to a file e.g. at /tmp, would that exhibit it?

    Since I don't know Ruby if you wouldn't mind throwing some simple test script like that together and pasting it in whole here, that would be a great start for getting my head around the problem. Thanks!

  • #!/usr/bin/ruby

    require 'rubygems' ## all of these are required You may need to install the crack ruby gem
    require 'crack'
    require 'open-uri'
    require 'rest-client'

    url='' # URL with JSON output to parse

    data = Crack::JSON.parse(RestClient.get(url)) # puts the JSON into an array

    data.each do |x| # loop

    target_file = 'foo.txt' # name of the file to be created/appended, "a") do |f| # create/open file and append with parsed JSON




    system ("open foo.txt") # This runs a command in the shell

    I pulled most of this example from:

    When I run the script from the shell, no problems.

    When I use FS I see this:

    Error Number:/Users/spayne/Library/Scripts/example.rb:16:in `initialize': Permission denied - foo.txt (Errno::EACCES)
    from /Users/spayne/Library/Scripts/example.rb:16:in `open'
    from /Users/spayne/Library/Scripts/example.rb:16
    from /Users/spayne/Library/Scripts/example.rb:12:in `each'
    from /Users/spayne/Library/Scripts/example.rb:12


  • Thanks, Seth. I was able to figure out what's going on with your example. The script is using a relative path "foo.txt" for the location of the temporary file to write to. That's fine if you're in the same directory as the script when you run it, but FastScripts doesn't make any effort to change to the directory of the script when it runs it.

    Try changing "foo.txt" to "/tmp/foo.txt" in both the line that sets the target_file variable, and in the line that does the system "open" call. This worked for me.
Sign In or Register to comment.