I'm trying to make my first steps with Gimp batch processing, but I'm stuck at the very beginning. I'm getting this error:
z80crews-iMac:~ z80crew$ /Applications/GIMP-2.10.app/Contents/MacOS/gimp -i -b '(do-it "france.png" "spain.png")' -b '(gimp-quit 0)'
batch command experienced an execution error:
Error: eval: unbound variable: do-it
do-it is the name of my function to execute. This function is defined in a file that's stored in ~/.gimp-2.10/scripts.
z80crews-iMac:~ z80crew$ cat ~/.gimp-2.10/scripts/gimp-combine-images.scm
(define (do-it fname-one fname-two)
)
z80crews-iMac:~ z80crew$ /Applications/GIMP-2.10.app/Contents/MacOS/gimp -v
GNU Image Manipulation Program Version 2.10.12
Additional info: Defining do-it right on the command line works:
z80crews-iMac:~ z80crew$ /Applications/GIMP-2.10.app/Contents/MacOS/gimp -i -b '((define (do-it fname-one fname-two)) (do-it "france.bigcities.png" "france.cities.png")' -b '(gimp-quit 0)'
batch command executed successfully
Other things I tried:
I tried to pass the script as an argument to gimp.
I opened the Gimp application and stored my script fu script in the directories that are shown in Preferences > Folders > Scripts.
I'm obviously missing something easy, but I can't find out what it is.
It seems this is the way to go:
I opened the Gimp application and stored my script fu script in the directories that are shown in Preferences > Folders > Scripts.
This time I launched and closed GIMP (the application with the GUI) after having put my script in /Users/USERNAME/Application Support/GIMP/2.10/scripts. This was the first path that GIMP lists in Preferences > Folders > Scripts.
Related
I’ve created the following simple test script
#!/bin/bash
echo "test"
I use chmod +x ./msa.sh to execute it.
Now, when I try to run it
like ./msa
I got the following error,
Failed to execute process ‘./msa.sh'. Reason:
exec: Exec format error
The file './msa.sh' is marked as an executable but could not be run by the operating system.
I'm using mac with fish, what should I do in order to run it successfully?
Are you sure you're saving the script as a plain text file? If you're using TextEdit you may be saving a RTF. Choose Format > Make Plain Text and resave the file if needed.
You can also examine the file from the shell to make sure it starts with the shebang line you're expecting. For example:
nicholas#mary ~> file msa.sh
msa.sh: Rich Text Format data, version 1, ANSI
nicholas#mary ~> head -1 msa.sh
{\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf400
That is not what you want.
nicholas#mary ~> file msa.sh
msa.sh: Bourne-Again shell script, ASCII text executable
nicholas#mary ~> head -1 msa.sh
#!/bin/bash
And that is what you want.
Very simple script to copy a file
#!/bin/bash
#copy file
mtp-getfile "6" test2.jpg
I set it as executable and run it using
sudo sh ./test.sh
It gives me a file called test2.jpg that has no icon and I cannot open I get a 'Failed to open input stream for file' error
However, if I simply issue the following from the command line
mtp-getfile "6" test2.jpg
It works as expected. What is wrong with my script? I checked and the resulting .jpg file in each case has the same number of bytes. Very strange.
As commented by chepner, your file might have a DOS (Windows) invisible line ending on its name, which would cause an error. To get rid of this unwanted character(s), just create a new blank script on your "nix" system and type the name by hand (not by copying and pasting, to avoid problems), let's say, name it test2.sh.
Then copy all the contents of test.sh to test2.sh (copy and paste) and run test2.sh and see if it works. If it doesn't, try running the following code on the new script, to make sure that there are no unwanted characters on the code itself:
tr -d "\r" < /folder/test2.sh && echo >> /folder/test2.sh
And then try to run script2.sh again to see if it works. Note: the echo >> /folder/test2.sh part of the code above is just to make sure that your new script ends with a newline, which is a Posix standard (and without which some programs may misbehave because they expect the file to end with a newline).
Apparently it was a permissions issue.
I only had to do a sudu chown test2.jpg
So, I have a problem. I have downloaded a program from the web. And it's a command line app. I have written a code, which generated some n-k commands to the app. I have written them into an output file. I can write an app in Python, but it freezes on some of the commands. I have tested them manually and seems like there are two issues:
Commands must be run one-by-one;
Some of the commands give an output like bla-bla-bla, this thing is not written into an output file. So, if I run a command ./app -p /file1 -o /file2 -s -a smth- > /fileOutput.txt The fileOutput.txt is empty, though in the terminal, there's is this bla-bla-bla message, stating, that something is wrong. If the command gives bla-bla-bla the app may freeze for a while.
Here is what I want to do:
CD into folder, the containing app;
For command in fileWithCommands perform command and start the next, only when the previous finishes;
If the command gives message, containing bla-bla-bla (cause it may look like file1 bla-bla-bla), write the command and this strange output into file badOutputs.txt.
Have never done applescript before. However, this's what I've done so far:
set theFile to "/Users/MeUser/Desktop/firstCommand"
set fileHandle to open for access theFile
set arrayCommand to paragraphs of (read fileHandle)
#I have found the previous code here: http://alvinalexander.com/mac-os-x/applescript-read-file-into-list-array-examples
close access fileHandle
tell application "Terminal"
activate
do script "cd /Users/MeUser/Desktop/anApp/"
repeat with command in arrayCommand
do script command
end repeat
end tell
Though there's a problem, if in one window the commands make up a huge queue. Without window 1 cd and the command are in different windows. And I am still unable to save the output.
UPDATE
Did with accordance to #Mark Setchell's recommendations. So now I have such code:
set theFile to "/Users/meUser/Desktop/firstCommand"
set fileHandle to open for access theFile
set arrayCommand to paragraphs of (read fileHandle)
close access fileHandle
repeat with command in arrayCommand
do shell script "cd /Users/meUser/Desktop/App/; " & command
end repeat
To the command I have added the following:
2>&1 /Users/meUser/Desktop/errorOut.txt
However, the apple script says that a mistake of the app is the mistake of the script. I.e.: file corrupted, app fails. I want it to write into error file where has it failed and move to the next command, while the script just fails.
Maybe not a complete solution, but more than a comment and easier to format this way...
First Issue
Your command-line app which writes on the Terminal may be writing to stderr rather than stdout. Try redirecting stderr to the same place as stdout by using
./app -p ... > /FileOutput.txt 2>&1
Second Issue
You cannot do:
do shell script cd somewhere
do shell script do_something
because each do shell script will execute in a separate, unrelated process. So your first process will start - in the default directory like all processes - and correctly change directory and then exit. Then your second process will start - in the default directory like all processes - and try to run your command. Rather than that, you can do this:
do shell script "cd somewhere; do_something"
which starts a single process which changes directory and then runs your command line program there.
Issue Three
Why do you want to send your commands to Terminal anyway? Does the user need to see something in Terminal - seems unlikely because you want to capture the output, don't you? Can't you just run your commands using do shell script?
Issue Four
If you want to keep your normal output separate from your error output, you can do:
./app ... params ... > OutputFile.txt 2> errors.txt
Suggestion 1
You can retain all the errors from all the scripts and accumulate them in a single file like this:
./app .. params .. >> results.txt 2>&1
That may enable you to deal with errors separately later.
Suggestion 2
You can capture the output of your shell script into an Applescript variable, say ScriptOutput, like this, then you can parse it:
set ScriptOutput to do shell script "..."
Suggestion 3
If errors caused by your script are stopping your loop, you can enclose them in a try block like this so they are handled and everything continues:
try
do shell script "..."
on error errMsg
display dialog "ERROR: " & errMsg
end try
I have a couple scripts to clean up some generated HTML; a python script using BeautifulSoup, and a Ruby script. These remove unneeded tags and attributes, transform symbols to html encodings, get rid of excessive newline characters, and make sure the files are encoded in valid UTF-8.
I can run these two scripts from the command line and they work as expected; and I can run them in this shell script from the command line:
#!/bin/bash
HTMLPath=$1
echo $HTMLPath 2>&1 >> /Users/me/Desktop/log.txt
/usr/bin/python /Users/me/DevProj/script/cleanHTML.py "$HTMLPath" 2>&1 >> /Users/me/DevProj/logs/log.txt
/Users/me/.rvm/rubies/ruby-1.9.3-p374/bin/ruby /Users/me/DevProj/script/cleanupHtml.rb "$HTMLPath" 2>&1 >> /Users/me/DevProj/logs/log.txt
and this also gives the expected result.
However when I run them from Automator, which feeds them a list of html files to process, the python script removes the html encoding − from the file (HTML encoding for minus symbol -) and I end up with white space instead. The problem is, I need those minus signs to remain, preferably as − and I need it to be run from Automator.
I thought it might have something to do with the version of python that the Automator shell was using, so I created the shell script to ensure it would use same bash shell I use on the command line, /bin/bash.
Has anyone else out there run into this issue? Am I doing something wrong from Automator?
In the script I have added python --version >> log.txt but it won't output the python version to the log... I have a sneaking suspicion that Automator is using its own older python library.
Note: I have only encountered this problem when there are − strings in the input file. It otherwise runs fine from Automator. Automator is causing the problem.
I have written an install script in shell that does some configuration of various things such as xserver, network, etc and then installs a few RPM's which is no problem. But I want to be able to log everything that goes to the terminal screen as well. Is this possible to do from within the script so if the end user runs ./Install.sh it will do everything (including the logging).
I have tried using "script" but doesn't work from within the Install.sh script itself.
Thanks
Just use:
script logfilename install.sh
when the install.sh finished the run, the script end too - so, you get everything logged into logfilename.
Probably you can make it two-stage, so, you should rename your current install.sh into install-stage2.sh and your install.sh will contain:
script ./install.log ./install-stage2.sh
UPDATE from my man script
NAME
script -- make typescript of terminal session
SYNOPSIS
script [-akq] [-t time] [file [command ...]]
DESCRIPTION
The script utility makes a typescript of everything printed on your terminal. It is useful for students who need
a hardcopy record of an interactive session as proof of an assignment, as the typescript file can be printed out
later with lpr(1).
If the argument file is given, script saves all dialogue in file. If no file name is given, the typescript is
saved in the file typescript.
If the argument command is given, script will run the specified command with an optional argument vector instead
of an interactive shell.