Automator Finder Service keeps on running, should run only once - finder

I've created a simple service using automator, that takes a *.tiff, creates a *.jpg out of it and than deletes the original.
However, I run this on a *.tiff file, it keeps on running, meaning it keeps on converting the (then jpg) file over and over again. That is, I believe it does, since the file disappears and reappears about 2 times a minute and the timestamp changes. How do I tell it to run the service (i.e. the shell commands) just once?
The Service in Automator is just this one action of type "run Shell-Script". The Shell script is
newName=${#%.tiff}.jpg
echo "$newName"
sips -s format jpeg "$#" --out "${newName}"
rm "$#"
Thanks!
(Would have posted a picture of the Automator window, but was not allowed to)

This behavior seems to be a folder actions.
if you created a folder action :
1- You must filter the TIFF files for that folder action doesn't process the created JPEG file.
2- You must use a loop, if you drop one or more files in that folder.
3- Use "&&" to delete the TIFF file only when the sips command finishes successfully.
Here's the script:
for f in "$#";do
if [[ "$f" = *.tiff ]]; then
sips -s format jpeg "$f" --out "${f%.tiff}.jpg" && rm "$f"
fi
done

Related

Library compiled to architecture x64 with error in Arm architecture

I'm developing a C++ library that has a piece of shell script code that return the name of a specific serial port. When I run this script in console either X64 desktop or Arm enviorment the script returns the right answer. My problem ocur when I execute the same script inside of the library, the returns shows bad formed string like ÈÛT¶ÈÛT¶¨a , but the expected is /dev/ttyACM0.
The script that run inside of library:
Script
bash -c 'for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev);do(syspath="${sysdevpath%/dev}";devname="$(udevadm info -q name -p $syspath)";[[ "$devname" == "bus/"* ]]&& continue;teste="$(udevadm info -q property --export -p $syspath | grep -i "company_name")";if [[ ! -z "${teste// }" && $devname == *"ttyACM"* ]]; then echo "/dev/$devname";fi);done;' 2> /dev/null
The following piece of code is used to save the content returned by the script into a file.
code c++
pfFile = fopen(CONFIG_FILE, "w+");
fwrite(result,strlen(result), 1, pfFile);
fclose(pfFile);
return 0;
Besides you didn't include what is result and where it comes from in your C++ code; you selected the hardest way to do this. Code running shell scripts inside a library most likely cause nothing but headaches.
Basically you can create an udev rule for your device to create an unique and stable file in /dev to access it. You can create one like this one in the ArchWiki
KERNEL=="video[0-9]*", SUBSYSTEM=="video4linux", SUBSYSTEMS=="usb", ATTRS{idVendor}=="05a9", ATTRS{idProduct}=="4519", SYMLINK+="video-cam1"

Sublime Text3: LaTeX Tools with Custom Command not working correctly

I needed to customize the settings from LaTeX tools, so that the glossaries package works.
Now everything works fine. But I also want to have the temporary files in one folder and the produced PDF at the .tex file.
The first thing works fine: Everything is in the build folder. But I can't get the PDF File out of this folder because my quotes will be deleted in the script commands.
Here are my script commands for building:
"script_commands": [
"latexmk -cd -e -f -pdf -synctex=1 -interaction=nonstopmode -auxdir=build -outdir=build",
"makeglossaries -d build",
"latexmk -cd -e -f -pdf -synctex=1 -interaction=nonstopmode -auxdir=build -outdir=build",
"move /y \"build/$file_base_name.pdf\" \"$file_base_name.pdf\"",
"move /y \"build/$file_base_name.synctex.gz\" \"$file_base_name.synctex.gz\"",
// "move /y \"build/$file_base_name.log\" \"$file_base_name.log\""
]
The first three commands works fine. The PDF gets correctly build. But the move command does not work.
I've also tried to use the full path but the problem was that I can't do a \ sign so that the call looked like move /y C:\path\to\the\texdocument/build/Document.pdf which also not worked.
I've also tried to use the ' signs. And copy as a replacement for move. But doesn't help.
Can someone help me?
P.S.: I'm using Windows.
// Edit: I've also a question regarding the Logoutput: Is it possible to show Errors and Warning via LaTeX Tools? Like the built in builders?
This is now the script-building system.
Thanks
Your script does not work, because LaTeXTools sets shell to False when calling the build command. Hence you can only call programs and not shell commands like move. If you have Cygwin or Coreutils installed they ship the mv program, which is the unix move command. It is installed as a program rather than a command and can be used in the builder.
Just change your build to:
"script_commands": [
"latexmk -cd -e -f -pdf -synctex=1 -interaction=nonstopmode -auxdir=build -outdir=build",
"makeglossaries -d build",
"latexmk -cd -e -f -pdf -synctex=1 -interaction=nonstopmode -auxdir=build -outdir=build",
"mv -f \"build\\$file_base_name.pdf\" \"$file_base_name.pdf\"",
"mv -f \"build\\$file_base_name.synctex.gz\" \"$file_base_name.synctex.gz\"",
"mv -f \"build\\$file_base_name.log\" \"$file_base_name.log\""
]
To answer your additional question:
If you have the log file available it will automatically parse and show errors and warnings.

How to launch terminal in a specific folder?

I've tried both launching /Applications/Utilities/Terminal.app/Contents/MacOS/Terminal as a process and using std::system to launch it from sh script (open -a /Applications/Utilities/Terminal.app/Contents/MacOS/Terminal) with different arguments (detsdir as argument, cd destdir etc.). Nothing works. It either opens in ~/, or it says "destdir is a directory` and logs off.
I've also tried launching it as a process with destdir set as working directory (using QProcess::startDetached). No luck either, it opens in ~/.
You can do it like this, with osascript:
osascript -e "tell application \"Terminal\" to do script \"cd ~/Desktop\""
This will create a new terminal window with working directory ~/Desktop.
QProcess has method setWorkingDirectory()

nohup ./startup & Permission Denied

I successfully compiled a MUD source code, and it says in the instructions to start up the server using
nohup ./startup &
although when I do this it gives me this error:
$ nohup: ignoring input and appending output to `nohup.out'
nohup: failed to run command `./startup': Permission denied
I have looked all over the internet to find the answer. A few of them said to put my cygwin directory in the root folder (I am using windows 7) and its directory is C:\cygwin
so thats not a problem.. Can anyone help me with this please??
Try chmod +x startup, maybe your startup file is not executable.
From "man nohup":
If the standard output is a terminal, all output written by the named
utility to its standard output shall be appended to the end of the
file nohup.out in the current directory. If nohup.out cannot be
created or opened for appending, the output shall be appended to the
end of the file nohup.out in the directory specified by the HOME
environment variable. If neither file can be created or opened for
appending, utility shall not be invoked. If a file is created, the
file's permission bits shall be set to S_IRUSR | S_IWUSR.
My guess is that since "sh -c" doesn't start a login shell, it is inheriting the environment of the invoking shell, including the HOME environment variable, and is trying to open it there. So I would check the permissions of both your current directory and $HOME. You can try to touch test.txt in current directory or $HOME to see if you can perform that command.
As staticx writes, check the permissions of the directory (and the user) - and the executable.
Instead of using nohup:
check if nohup is needed at all, try ./startup </dev/null >mud.out 2>mud.err &, then close the terminal window and check if it is running
or just run ./startup in a screen session and detach it (<ctrl>+<a>,<d>)

batch file to check existance of directory if not exists then use alternate directory for file copy

I am trying to write a batch file that copies an exe file from a network location to a local location. It currently works but depending on windows version (xp or win7) the user has to select the correct .bat file due to different local paths needed for the copy. (they are going to the startup folder to be ran every time user starts machine). This is the first time i've ever worked with writing batch files and am completely lost when looking at the syntax for if statements. If i could get some help figuring this out it would be great.
Here is what I currently have that works for XP:
REM #ECHO OFF
ECHO STARTING MOVEFILES
SET EXITRC=0
SET EXITMSG=EXITRC INITIALIZED
ECHO %EXITRC% -- %EXITMS
COPY "\\networkDrive\install\Individual\program\MOVEFILES.EXE" "C:\DOCUMENTS AND SETTINGS\ALL USERS\START MENU\PROGRAMS\STARTUP\"
ECHO COPIED FILES TO YOUR PC
SET EXITRC=%ERRORLEVEL%
IF NOT %EXITRC% == 0 GOTO :EXIT
SET EXITMSG=PROCESSING COMPLETE
:EXIT
ECHO STEP: %EXITMSG% RC: %EXITRC%
ECHO FINISHING MOVEFILES
PAUSE
EXIT %EXITRC%
Here is what I have for Windows 7:
#ECHO OFF
ECHO STARTING MOVEFILESWIN7
SET EXITRC=0
SET EXITMSG=EXITRC INITIALIZED
ECHO %EXITRC% -- %EXITMS
COPY "\\networkDrive\install\Individual\program\MOVEFILES.exe" "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup"
ECHO COPIED MOVEFILESWIN7 TO YOUR PC - All Users / Public Startup folder
SET EXITRC=%ERRORLEVEL%
IF NOT %EXITRC% == 0 GOTO :EXIT
SET EXITMSG=PROCESSING COMPLETE
:EXIT
ECHO STEP: %EXITMSG% RC: %EXITRC%
ECHO FINISHING MOVEFILESWIN7
PAUSE
EXIT %EXITRC%
I would like to have only one batch file that will cover both scenarios so there is no confusion to the user on which batch file to run.
You can utilise the environment variable %ALLUSERSPROFILE%.
On WinXP the default is C:\Documents and Settings\All Users
On Win7/2008 the default is C:\ProgramData
There is a table available here: http://ss64.com/nt/syntax-variables.html
I see you also copy a different file. Not sure why you do that. Maybe you could detect using a method here: https://stackoverflow.com/a/2788764/1553090 -- Otherwise perhaps you should take advantage of the %ProgramFiles% and %ProgramFiles(x86)% variables.
Just to elaborate on how you might choose to use these variables... You can test the Win7 startup folder for existence, and if it's not there just fallback to the XP (regardless of whether it exists).
set STARTUP_WIN7=%ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Startup
set STARTUP_WINXP=%ALLUSERSPROFILE%\Start Menu\Programs\Startup
if EXIST "%STARTUP_WIN7%" (
set STARTUP=%STARTUP_WIN7%
) else (
set STARTUP=%STARTUP_WINXP%
)