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"]
File.open(target, "a") do |f| f.write(content) end end
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
1
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!
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.