How can I force AutoLISP application to wait until application run by startapp will finish his work - autocad-plugin

In my AutoCAD LISP plugin I run external application by startapp then need to do some action after external application will be closed. How can I do it? maybe I can substitute startapp by something else?

AutoCAD Lisp is executed asynchronously.

There are at least two ways of synchronize it:
(setq Shell (vlax-get-or-create-object "Wscript.Shell"))
(setq updater(vlax-invoke-method Shell 'Exec (strcat apppath appname ) ))
(while ( = (vlax-get-property updater 'Status ) 0)
(Sleep 1000)
)
(vlax-release-object Shell)
or using Command:
(command "_Shell" (strcat apppath appname ) )

Related

run a custom script when called with no args

. Working language is python. I want to attach a shell script when no argument is given or on own option.
Sorry if there is any confusion..
The main working flow is im working on a commmad called kubectl. So if the user enters this command without any arguments(my own option on this command) then i want to execute a shell script.
You can override kubectl by a function to accomplish that. Just append the function below to your .bashrc.
kubectl()
case $* in
( kadalu ) /path/to/script ;;
( * ) command kubectl "$#"
esac

How to make exec command in shell script run in different process?

I'm working with this GUI application, GTKWave, that has a startup script, gtkwave, which I've added to my system path. At the very end of said script, there is this line:
$EXEC "$bundle_contents/MacOS/$name-bin" $* $EXTRA_ARGS
where $EXEC=exec
My problem is that given how exec works, my terminal is "hijacked" by the GUI process, meaning I can't run any more commands until I close the window, which is not ideal.
I currently got around this by putting this function in my .bash_profile:
function run-gtkwave ( ) { nohup gtkwave $1 &>/dev/null & }
While this works, it makes it hard to pass arguments to gtkwave. Ideally, I could do a form right before that exec command, but I'm not sure how to do that in bash. I know that the & character should do that, but
$EXEC "$bundle_contents/MacOS/$name-bin" $* $EXTRA_ARGS &
doesn't cut it, and neither does
"$bundle_contents/MacOS/$name-bin" $* $EXTRA_ARGS &
or
("$bundle_contents/MacOS/$name-bin" $* $EXTRA_ARGS) &
How do I modify this line to run the application in its own process?
You can make your run-gtkwave function pass arguments to gtkwave by changing the definition to:
function run-gtkwave { nohup gtkwave "$#" &>/dev/null & }
Since using nohup and output redirection stops the terminal being "hijacked", you might be able to fix the problem in gtkwave by doing the nohup redirection and the output redirection there. (If standard input is a terminal, nohup redirects it from /dev/null.) One possibility is:
"$bundle_contents/MacOS/$name-bin" $* $EXTRA_ARGS </dev/null &>/dev/null &
(I've omitted the $EXEC because I can't see any point in using exec and & together.)

How to launch two programs in parallel using a bash script

What I have:
#!/bin/bash
cd App && exp start
cd ~/Android/Sdk/emulator ./emulator &
But this just starts exp. I want it to start exp open another bash terminal and launch the emulator there. Any tips?
Here you go:-
#!/bin/bash
cd App || exit
#better always put a full path like /home/App/
exp start &
cd ~/Android/Sdk/emulator || exit
#better always put a full path
./emulator &
if you want to wait till both the process finish put wait at the end of the script
you can use for example nohup
like:
#!/bin/bash
cd App
nohup exp start > exp.log 2> exp.error.log &
cd ~/Android/Sdk/emulator
nohup ./emulator > emulator.log 2> emulator.error.log &
something like that

Tell an AppleScript to Restart Itself

I have an AppleScript saved as an application. When first run, it asks the user if they want to move it to the Applications folder. What I would like to be able to do is, after it's been moved, have the script quit itself and then reopen.
Obviously I can't say
tell me to quit
tell me to activate
...because it would stop running after the quit command.
Any suggestions?
Just run the script from inside the script, and make sure to terminate the current running of it with a return (can skip the actual return command if it's the last line of the script
-- do stuff
display dialog "Here I am again"
-- set alias to the script
-- run the script
set myScript to path to me
run script myScript
-- end current iteration
return
You can break out of this script by canceling the dialog, but you'll probably want to set a condition to check whether to run the script again.
Here's how I'd do this. Basically, You check if the application is running from the Applications folder. If it isn't, move it there, open another instance, and quit. Seems to work flawlessly. The activate in the beginning is because it seems that the application doesn't always move itself to the foreground:
--incase the application doesn't do this automagically
activate
set my_path to POSIX path of (path to me)
if my_path does not start with "/Applications/" then
set new_path to "/Applications/" & quoted form of (my name & ".app")
--"mv" wont move the application into the new location if it exists
try
do shell script "rm -rf " & new_path
end try
do shell script "mv -f " & quoted form of my_path & " " & new_path
do shell script "open -n " & new_path & " &> /dev/null &"
quit
end if
What I am doing.
First I enabled at by running the following command in Terminal (this only has to be done once)
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist
then I have the following script
display dialog "running"
set mypath to POSIX path of (path to me)
set lun to open for access POSIX file "/tmp/springboard" with write permission
write "open " & mypath & linefeed to lun
close access lun
do shell script "at -f /tmp/springboard +1 minute"
quit

How do you open a terminal with a specific path already cd'ed to?

How do I use the terminal to open another terminal window but with a path I specify?
I am using automator to load my work stuff when I get to work, but I need to know how to do this:
Open Terminal and Type:
• cd Work/Company/Project/
• script/server
And then new tab in that terminal window and cd to the same folder.
This opens a new terminal window from a command prompt on Mac OSX , executes "cd /" and then keeps the window on top:
osascript -e 'tell application "terminal"' -e 'do script "cd /"' -e 'end tell'
You can put this into a script like this:
#!/bin/sh
osascript -e 'tell application "terminal"' -e "do script \"cd $1\"" -e 'end tell'
Hope this helps.
Use an applescript to do this.
e.g. Open Terminal Here
You can write a shell script to cd to that directory
So write a script that executes something like cd /user/music or something like that, save it as myscript.sh and run it using chmod +x myscript.sh.
This resource from the OS X developer network is pretty helpful
The two scripts below together handle the common scenarios:
1) If Terminal is already running, open a new terminal window and run the 'cd mydir' there
2) If terminal is not already running, use the initial window that Terminal spawns (window 0), rather than annoyingly launching a second window
NOTE: what's not quite perfect is if Terminal has several windows open, all of them will be brought to the front, overlapping any other apps. A solution to raising only the last terminal window to the front appears to require the black magic of AppleScriptObjC - references below:
https://apple.stackexchange.com/questions/39204/script-to-raise-a-single-window-to-the-front
http://tom.scogland.com/blog/2013/06/08/mac-raise-window-by-title/
Script 1 - open a text editor and save as:
/usr/local/bin/terminal-here.sh
#!/bin/sh
osascript `dirname $0`/terminal-here.scpt $1 > /dev/null 2> /dev/null
Script 2 - open 'AppleScript Editor', paste contents below and save as:
/usr/local/bin/terminal-here.scpt
# AppleScript to cd (change directory) to a path passed as an argument
# If Terminal.app is running, the script will open a new window and cd to the path
# If Terminal.app is NOT running, we'll use the window that Terminal opens automatically on launch
# Run script with passed arguments (if any)
on run argv
if (count of argv) > 0 then
# There was an argument passed so consider it to be the path
set mypath to item 1 of argv
else
# Since no argument was passed, default to the home directory
set mypath to "~"
end if
tell application "System Events"
if (count (processes whose bundle identifier is "com.apple.Terminal")) is 0 then
# Terminal isn't running so we'll make sure to run the 'cd' in Terminal's first window (0)
tell application "/Applications/Utilities/Terminal.app"
# Turn off echo, run the 'cd', clear screen, empty the scrollback, re-enable echo
do script "stty -echo; cd " & (mypath as text) & ";clear; printf \"\\e[3J\"; stty echo" in window 0
activate last window
end tell
else
# Terminal is already running so we'll let it open a new window for our 'cd' command
tell application "/Applications/Utilities/Terminal.app"
# Turn off echo, run the 'cd', clear screen, empty the scrollback, re-enable echo
do script "stty -echo; cd " & (mypath as text) & ";clear; printf \"\\e[3J\"; stty echo"
activate last window
end tell
end if
end tell
end run

Resources