Sorry new to coding Applescript so any help is appreciated.
I'm trying to create a script that pastes text from clipboard into the middle of a telnet command. The output needs to be in the same window and look kind of like this:
I8,A,001
Q102,024
q448
rN
S4
D15
ZT
JF
O
R71,0
f100
N
B264,65,2,UA0,2,4,56,B,"100000000045"
A203,82,2,1,2,2,N,"xxxxx"
P1
The quoted 12 digit number on line 13 is what I need to insert.
This is what I've coded so far but it's not working:
tell application "Terminal"
do script "telnet xxx.xxx.xx.xx xxxx"
delay 1
do script "I8,A,001" in window 1
do script "Q102,024" in window 1
do script "q448" in window 1
do script "rN" in window 1
do script "S4" in window 1
do script "D15" in window 1
do script "ZT" in window 1
do script "JF" in window 1
do script "O" in window 1
do script "R71,0" in window 1
do script "f100" in window 1
do script "N" in window 1
do script "B264,65,2,UA0,2,4,56,B,\""
tell application "System Events"
tell application process "Terminal" in window 1
keystroke "v" using {command down}
end tell
keystroke "\""
keystroke return
do script "\"A203,82,2,1,2,2,N,\"xxxxx\""
do script "P1"
keystroke return
end tell
end tell
As soon as I try to use Command V to paste it exits the Terminal window and pastes whats on the clipboard on the script instead and it wont let me tell it to stay in Terminal window 1.
You do not need to use command-v to get the clipboard contents into your Terminal window. Applescript can get the clipboard and then you just add it to the other part of your string before "do script". Something like this works... of course you don't need the first line of the code because the clipboard should already have that value.
set the clipboard to "100000000045"
set t1 to "B264,65,2,UA0,2,4,56,B,\""
set t2 to the clipboard
set t to t1 & t2 & "\""
do script t in window 1
This is what I ended up using to get it to work in case anyone else needs it:
tell application "Terminal"
do script "telnet xxx.xxx.xx.xx xxxx"
delay 1
do script "I8,A,001" in window 1
do script "Q102,024" in window 1
do script "q448" in window 1
do script "rN" in window 1
do script "S4" in window 1
do script "D15" in window 1
do script "ZT" in window 1
do script "JF" in window 1
do script "O" in window 1
do script "R71,0" in window 1
do script "f100" in window 1
do script "N" in window 1
set t1 to "B264,65,2,UA0,2,4,56,B,\""
set t2 to the clipboard
set t to t1 & t2 & "\""
do script t in window 1
do script "A203,82,2,1,2,2,N,\"xxxxx\"" in window 1
do script "P1" in window 1
end tell
Thanks for the help regulus!
Related
I'm trying to do an apple script that can do the following:
I have an icon SVG called "bubble.svg" in a folder in a folder called "test" in the desktop.
Is it possible to create an apple script to change the hex colour of the icon so that when I will run the script it will prompt me a window to include the new HEX colour of the icon, and copy the svg with the new colour to the clipboard so that I can past it in application with the new colour?
I used the following code and get this error
on run
set theHex to text returned of (display dialog "Enter the new HEX color for the icon:" default answer "#FFFFFF")
set theFile to (choose file with prompt "Select the SVG file to modify:")
set theFileContents to read file theFile
set theFileContents to (do shell script "sed 's/#000000/" & theHex & "/g' < " & theFile)
set theFile to open for access theFile with write permission
write theFileContents to theFile starting at eof
close access theFile
set the clipboard to theHex
end run
In can include the new colour and the select the file, but then I get the following error
ERROR error "sh: Macintosh: No such file or directory" number 1
Can you help me?
Thank you!
I used the following
on run
set theHex to text returned of (display dialog "Enter the new HEX color for the icon:" default answer "#FFFFFF")
set theFile to (choose file with prompt "Select the SVG file to modify:")
set theFileContents to read file theFile
set theFileContents to (do shell script "sed 's/#000000/" & theHex & "/g' < " & theFile)
set theFile to open for access theFile with write permission
write theFileContents to theFile starting at eof
close access theFile
set the clipboard to theHex
end run
I have this problem every time I use a ( or any of " ' { [. I have plugin that automatically closes it by corresponding ) " ' } ] but I am stuck inside the parenthesis or inside double quotes
String s="I completed typing the string but my cursor is stuck right here |";
I want exit the enclosure by pressing something for all. In VScode I can press the same symbol if my cursor is right behind it and it gets past the enclosure or by pressing tab
I can exit the enclosure without reaching for right arrow
If your plugin is 'jiangmiao/auto-pairs' it has a variable called g:AutoPairsShortcutJump you can set as you want or use the default tha is Altn.
" Jump outside '"({
" -> default Alt-n
if !exists('g:AutoPairsShortcutJump')
let g:AutoPairsShortcutJump = '<A-l>'
endif
Note: If your cursor it close to the end atom you can just repeat that one to jump outside. For example:
Let's supose the character `|' represents your cursor
(|)
Just press closing parenthesis will jump outside
Am new to bash and whiptail so excuse the ignorance.
When assigning a var in the for loop, the new value of 20 is never set when using a Whiptail dialog. Any suggestions why ?
andy="10"
{
for ((i = 0 ; i <= 100 ; i+=50)); do
andy="20"
echo $i
sleep 1
done
} | whiptail --gauge "Please wait" 5 50 0
# }
echo "My val $andy
A command inside a pipeline (that is, a series of commands separated by |) is always executed in a subshell, which means that each command has its own variable environment. The same is true of the commands inside the compound command (…), but not the compound command {…}, which can normally be used for grouping without creating a subshell.
In bash or zsh, you can solve this problem using process substitution instead of a pipeline. For example:
andy="10"
for ((i=0 ; i <= 100 ; i+=50)); do
andy="20"
echo $i
sleep 1
done > >(whiptail --gauge "Please wait" 6 50 0)
echo "My val $andy
>(whiptail ...) will cause a subshell to be created to execute whiptail; the entire expression will be substituted by the name of this subshell's standard input (in linux, it will be something like /dev/fd/63, but it could be a FIFO on other OSs). > >(...) causes standard output to be redirected to the subshell's standard input; the first > is just a normal stdout redirect.
The statements inside {} are not ordinarily executed in a sub-shell. However, when you add a pipe (|) to it, they seem to be executed in a sub-shell.
If you remove the pipe to whiptail, you will see the update value of andy.
I'm trying to create a script so that during a task my keyboard/mouse is restricted from use aswell as whilst waiting for something what doesn't have a trigger/way of detecting if it's done I need it to stop me or anyone from moving the mouse/typing for at least 40 seconds.
Would this be possible to do in autoit and if so does anyone know how I can acheive this?
thanks GTPE
You're looking for BlockInput() which allows you to block keyboard and mouse from doing anything, the overriding command is: CTRL + ALT + DELETE
Basically just put BlockInput(1) at the start which will stop all keyboard/mouse from functioning
Then at the end put BlockInput(0) which releases control and allows you to do what you want.
60 Second BlockInput
BlockInput(1)
$timer = 60
For $i = 1 To $timer Step +1
Sleep(1000)
$Coords = MouseGetPos()
ConsoleWrite($timer - $i & " seconds Remaining" & #CRLF)
TrayTip("Keyboard & Mouse Frozen", $timer - $i & " seconds Remaining", 1)
ToolTip($timer - $i & " seconds Remaining", $Coords[0], $Coords[1], "Keyboard & Mouse Frozen")
Next
BlockInput(0)
I added notifications using ConsoleWrite, TrayTip and ToolTip just so that it doesn't freeze and confuse you.
Psst: This bit of code is fantastic for when you want to clean a keyboard without unplugging it or turning the computer off :P
UPDATE:
There was an obvious debugging step I forget. What happens if I try a command like ps &
in the regular old bash shell? The answer is that I see the same behavior. For example:
[ahoffer#uw1-320-21 ~/program1]$ ps &
[1] 30166
[ahoffer#uw1-320-21 ~/program1]$ PID TTY TIME CMD
26423 pts/0 00:00:00 bash
30166 pts/0 00:00:00 ps
<no prompt!>
If I then press Enter, the command shell reports the exit status and the console displays the exit status and the prompt:
[ahoffer#uw1-320-21 ~/program1]$ ps&
[1] 30166
[ahoffer#uw1-320-21 ~/program1]$ PID TTY TIME CMD
26423 pts/0 00:00:00 bash
30166 pts/0 00:00:00 ps
[1] Done ps
[ahoffer#uw1-320-21 ~/program1]$
PS: I am using PuttY to access the Linux machine via SSH on port 22.
ORIGINAL QUESTION:
I am working on a homework assignment. The task is to implement part of a command shell interpreter on Linux using functions like fork(), exec(). I have a strange bug that occurs when my code executes a command as a background process.
For example, in the code below, the command ls correctly executes ls and prints its output to the console. When the command is finished, the The event loop in the calling code correctly prints the prompt, "% ", to the console.
However, when ls & is executed, ls executes correctly and its output is printed to the console. However, the prompt, " %", is never printed!
The code is simple. Here is what the pseudo code looks like:
int child_pid;
if ( (child_pid=fork()) == 0 ) {
//child process
...execute the command...
}
else {
//Parent process
if( delim == ';' )
waidpid(child_pid);
}
//end of function.
The parent process blocks if the delimiter is a semicolon. Otherwise the function ends and the code re-enters the event loop. However, if the parent sleeps while the the background command executes, the prompt appears correctly:
...
//Parent process
if( delim == ';' ) {
waidpid(child_pid)
}
else if( delim == '&' ) {
sleep(1);
//The prompt, " %", is correctly printed to the
// console when the parent wakes up.
}
No one in class knows why this happens. The OS is RedHat Enterprise 5 and the compiler is g++.