I'm trying to run this script to change my wallpaper but I'm running into issues when the path for the file is in a variable
sh run.sh
wallpaper_path="$(pwd)/assets/wallpaper.jpg"
osascript -e 'tell application "Finder" to set desktop picture to POSIX file "$(wallpaper_path)"'
33:48: execution error: Finder got an error: AppleEvent handler failed. (-10000)
On the other hand absolute paths work fine
osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/Users/stupifatcat/workspace/project/assets/wallpaper.jpg"'
Does anyone have any idea what I'm doing wrong?
Single quoting the string prevents the variable from being expanded. You will need to use additional single quotes to demarcate the string(s), or switch to double quotes and escape as needed:
osascript -e 'tell application "Finder" to set desktop picture to POSIX file "'$wallpaper_path'"'
or
osascript -e "tell application \"Finder\" to set desktop picture to POSIX file \"$wallpaper_path\""
Also note that the $() form is a command substitution.
Related
I am trying to run "cd Desktop" in the terminal if the Desktop folder exists. Here is my current code:
tell application "Terminal"
activate
try
if exists folder "Desktop" then
do script "cd Desktop" in tab 1 of window 1
end if
do script "java -jar /Users/Harry/Desktop/Candle.app/Contents/candle.jar" in tab 1 of window 1
on error
if exists folder "Desktop" then
do script "cd Desktop"
end if
do script "java -jar /Users/Harry/Desktop/Candle.app/Contents/candle.jar"
end try
end tell
I am very new to apple script, so I don't know why this calls a syntax error when saved/compiled. Can anyone help??? Thanks.
AppleScript is a fairly minimal language, and relies on other applications to perform stuff that it doesn't know about.
You are getting the error because Terminal doesn't know what the term folder is. Something like Finder or System Events can be used to handle file objects, and you can also coerce the path to an alias, which will error if it does not exist - note that your usage of the term exists in this case would be from the standard suite, which is for general objects, so it will return true since the string does exist.
Also note that each do script statement will be in its own window unless otherwise specified. I think you are looking for something more like:
set theFolder to "/Users/you/Desktop"
tell application "Finder" to set folderExists to exists (folder theFolder as POSIX file)
if folderExists then
tell application "Terminal"
activate
try
do script "cd Desktop" in tab 1 of window 1
on error errmess
log errmess
do script "cd Desktop"
end try
delay 0.05
do script "echo testing" in tab 1 of window 1
end tell
else
beep
end if
I have below two file to start and stop my spring-boot application. Is it possible to have this installed as server etc in unix? so that I can just type start app or stop app to start or stop my application from any location?
startApplication.sh
stopApplication.sh
You can always define alias in your bash, do as below:
sudo vim ~/.bashrc
go at the end of file and add this line
alias start-app='bash /<path-to-script>/startApplications.sh'
save and exit and resource it with source command
source ~/.bashrc
now if you type in your terminal start-app it will execute your script. create one for stop-app too.
I am running the following command format:
PsExec.exe -i -s \\\\ip -u username -p password "\\\\shared\driver\path\autoitscript.exe" "\\\\shared\driver\path\car.jpg"
The exe file takes in a file path and enters the path in a file upload window. The exe file is an AutoIt script (.au3 file converted). The script uses ControlSetText to enter the file path in the upload window. I can see the exe file being run on the remote machine, but for some reason the file path is not being entered. Is there something wrong in the way i execute the psexec command? Locally the script executes correctly.
I was using ControlSetText to send the file path into the upload window. That did not work. Instead use ControlSend or Send.
My problem is in two parts:
My team and I are using an Test Design Studio to write .vbs files in a Accurev Workspace. The problem is that Accurev recognize them as binaries instead text/ptext files... which causes problems when merging. Is there a setting in Accurev I can change to force it to recognize .vbs files as text/ptext?
All those binaries that are already in the stream, I need solution to convert them all into text/ptext. I've given up on the Client UI, because it means I'd have to go in the Workspace explorer and go through every single folder, one by one, and keep those binaries. Then I thought of the commands. I tried
2.1. accurev keep -c "keep ptext" -n -E ptext -R target_folder
2.2. accurev keep -c "keep ptext" -n -E ptext -R .
2.3. But I get a No Element Selected. That's because the "-n" flag is required for recursive, but it means it'll ignore non-modified files... and most of my files are backed and not modified... otherwise I can't even select the directory for keeping (I'll report "can't keep a directory"). I could create a file-list, but it would take as long as manually keeping all the files one by one. I also tried if I could work directly in the stream (since it has another empty stream above, it lists all it's files as outgoing), but I do not have the keep option in the stream. Is there an easy way to convert all files in stream/workspace as text/ptext?
Yes, you will need to enable a pre-create-trigger using the elem_type.pl script found in "accurev install dir/examples" on your server. Inside the elem_type file, you will see the directions for setting this trigger.
Yes, run the following command to generate a list of all the files in your workspace.
"accurev stat -a -ffl > list.txt"
Then run the this command to convert the files to ptext:
"accurev keep -c "ptext conversion" -E ptext -l list.txt"
Then you can promote those files.
Check the files with a hex editor to see if there are any non-ASCII characters.
If there's binary content in the file AccuRev will see those files as binary.
Overwrite the keep as jstanley suggested to change the type.
On the add use "accurev add -E ptext -c "your favorite comment" file.vbs
I am trying to convert a PDF document into a PNG file using ImageMagick command line tools from a ASP.NET website. I create a new shell process and ahve it execute the following command:
convert -density 96x96 "[FileNameAndPath].pdf" "[FileNameAndPath].png"
This runs well when testing the website on my local machine with the ASP.NET Develeopment Server of VS and the command also works well when manually entered into the shell. When running from the programatically created shell in ASP.NET there is the following error message:
Invalid Parameter - 96x96
Does anybody know why that happens and what to do?
I have tested the command while being logged in on the server via RDP with a different user account than the ASP.NET process. I have used exactly the same ImageMagick and Ghostscript installation files as on my local machine and have activated adding the ImageMagick installation path to the enironment variables during installing. The server has not been rebooted since than.
convert is also the name of a windows executable which converts FAT filesystem to NTFS. When you do not specify the full path of an executable, quote:
...the system first searches the current working directory and then
searches the path environment variable, examining each
directory from left to right, looking for an executable filename that
matches the command name given.
"C:\Windows\System32" is generally present in the beginning of %PATH% variable, causing the Windows convert utility to launch, which fails with "Invalid Parameter" error as expected.
Try specifying the full path of the ImageMagick's convert.exe like so:
"C:\Program Files\ImageMagick\convert.exe" -density 96x96 "path_and_filename.pdf" "path_and_filename.png"
As others have stated convert points to a different program in your PATH. Instead preface your command with magick. So your command would instead be:
magick convert -density 96x96 "[FileNameAndPath].pdf" "[FileNameAndPath].png"
In Window actually exists a "convert.exe" in system32 - make sure your script doesn't start that one (maybe the environment paths on your development machine are set differently).
I am only answering this late because imagemagick was updated. Now, if you wish to use the "convert" command, you do it like this:
magick convert "image.png" "document.pdf"
or
magick convert "image_00*.png" "document.pdf"
for multiple images.
Same syntax for command, just add magick before it
A couple more options for fixing this:
Edit your Path system variable to contain the path to imagemagick
as it's first content and then add the rest after it. This will make
windows always find the imagemagic convert first before it finds
the other convert program. So something like this: C:\Program Files\ImageMagick-6.9.2-Q16;C:\Program Files\Haskell Platform\2014.2.0.0\lib\extralibs\bin;...
Another option is to create a dedicated folder somewhere on your machine where you will place shortcuts for some of these name clashes. Then what you do is that you rename those shortcuts to meaningful names, for example convert_image_magick, then add the path to this folder to your system path. So now as you hit tab more, you will finally find the right program you want to run
yes! if you launch an Administrator command window it defaults to C:\windows\sytem32\ ... as long as you're not in that directory the command will pickup the ImageMagick convert.exe
My issue was I was using the "FORFILES" command which is tricky because it requires using
"cmd /c" and passing the convert command with #path and #file parameters and it does some escaping of slashes... needless to say it's caused me hours and hours of headache. It even parses hex characters, like if your filepath has the combination 0x00 in it, it will think that's a hex value and mangle your path. I had a filepath named C:\ImageRes3000x3000
and FORFILES interprets that literally and it caused a strange path issue. Sorry if this is a long useless post but it's meant to be FYI, if someone runs across this, maybe it will help them. That being said, FORFILES and "convert.exe" are a powerful and simple image renaming line script combo.
here's my full 3 line image renaming script
robocopy D:\SRC_DIR\ D:\DEST_DIR\_staging *.jpg /e /MAXAGE:2
FORFILES /P D:\DEST_DIR\_staging\ /S /M *.jpg /C "cmd /c convert.exe #path -quality 65 -resize 1500 D:\RESIZED_DIR\\#file"
DEL D:\DEST_DIR\_staging\*.* /S /Q