Repeat scripts at same time in one script/application in Applescript
I have run into a problem while coding this troll program.
What I want to do is turn volume up without the victim to be able to turn it down and run a script at same time (in one script/application). I don't know how to combine these scripts into one and have them run at the same time. This is the script.
on run {input, parameters}
tell application "Google Chrome"
activate
open location "https://youtu.be/sZFOwzEFYRA"
repeat
delay 0.1
display dialog "Looooooolz" buttons {"Looooool", "Looolzz"}
if result = {button returned:"Looooool"} then
if exists window "https://youtu.be/sZFOwzEFYRA" then
open location "https://youtu.be/sZFOwzEFYRA"
end if
else
if exists window "https://www.youtube.com/watch?v=igfJIZayiy8" then
open location "https://www.youtube.com/watch?v=igfJIZayiy8"
end if
end if
end repeat
end tell
return input
end run
second script:
on run {input, parameters}
repeat
set volume output volume 100
end repeat
return input
end run
I don't think you can do that with pure AppleScript. However, you can get a similar effect using the combination of AppleScript and a shell script. Here's an example AppleScript that will display two dialogs in independent repeat loops. The "&" at the end of the first osascript command is the key to getting them running concurrently.
do shell script "#!/bin/bash
osascript -e 'repeat
display dialog 1
end repeat' &
osascript -e 'repeat
display dialog 2
end repeat'"
You should be able to extend this idea to have your two scripts doing whatever terrible things you want.
Related
I need the applescript to run tabset test command to change the name of the current tab of iTerm.
-- Launch iTerm and log into multiple servers using SSH
tell application "iTerm"
activate
create window with default profile
set newWindow to (create window with default profile)
set Servers to paragraphs of (do shell script "/bin/cat $HOME/serverlist")
repeat with nextLine in Servers
if length of nextLine is greater than 0 then
tell current window
create tab with default profile
tell current session of newWindow
do shell script "export PATH='/usr/local/bin:$PATH'; tabset test "
end tell
end tell
end if
end repeat
tell first tab of current window
close
end tell
tell second window
close
end tell
end tell
The problem is tabset test does not work, and there is no any error prompted.
The tabset command could be installed via npm install -g iterm2-tab-set
Ted Wrigley is right. I should use iTerm's write command to type the text into the window.
I have a tiny Bash script that executes ffmpeg and a touch command on an input file. I use this to recompress video files from my camera. I would like to be able to right-click files in Finder and run the script on the select file(s), preferably showing the terminal window while executing and closing when done.
How to do this on macOS?
I think this is what you want. I started Automator by pressing ⌘space and starting to type "Automator", hitting ↩ as soon as it guessed correctly. I then created a "Quick Action" that contains this code:
on run {input, parameters}
repeat with theItem in input
set f to POSIX path of theItem
tell application "Terminal"
activate
tell window 1
do script "echo " & f
end tell
end tell
end repeat
end run
and looks like this:
It basically just echos the filename, but you can put ffmpeg commands in there instead.
Why using finder? Or automator? Or going though loops and hoops just to use the GUI?
You have fully-functional bash shell in MacOS, so save time and hassle with the below one-liner.
Assuming you need to run your script for all *.mpeg files in the folder.
Try this:
ls *mpeg | xargs <your_script_name>
You will see the execution output in the same terminal window.
I need to write a simple applescript that will be opened with an argument. That argument will be a file path. I need it to save this file path to a text file. I want to avoid using shell script.
I'm finding this surprisingly difficult, despite having done it in .sh and .bat already
Thanks very much!
Adam
//// the current code which is not working is below. the code begins with "on run" and ends with "end run" but for some reason this isn't being highlighted as code
on run argv
set this_PATH to (POSIX file argv)
tell application "TextEdit"
activate
make new document
set text of document 1 to this_PATH as text
save document 1 in "/Users/adamparkinson/Desktop/date.txt"
end tell
end run
I made this work:
#!/usr/bin/osascript
on run argv
tell application "TextEdit"
activate
make new document
tell document 1
set its text to (item 1 of argv as text)
save in posix file (item 1 of argv as text )
end tell
end tell
end run
I called it like this:
./SavePath.sh /Users/Me/Desktop/junk/Newstuff.txt (Of course I used chmod u+x SavePath.sh to make it executable.)
If this works for you, then please check of my answer as answered. :)
with applescript it is very easy to create application Drag and Drop without any script shell below a version Drag and Drop of your script
on open draggedItems
set this_PATH to quoted form of POSIX path of draggedItems
repeat with currentItem in draggedItems
tell application "TextEdit"
activate
set doc to open POSIX file "/Users/adamparkinson/Desktop/date.txt"
make new word at end of text of doc with data (this_PATH as text) & return
end tell
end repeat
end open
I have an automator workflow. How can I make it restart the workflow in an if statement?
on run {input, parameters}
if (input as text) is "" then
-- restart workflow
end if
return input
end run
Without AppleScript
At the end of automator workflow, put Loop. (Loop is in Library > Utilities) Loop has an option Ask to Continue. If the user click Continue, Automator will restart the workflow. If not, the next process after the Loop will be executed.
With AppleScript
At the end of automator workflow, put Run AppleScript and Loop. Set the Loop option to Loop automatically and Stop After 1000 times. The AppleScript code is as follows.
on run {input, parameters}
if (input as text) is "" then
tell me to quit
end if
return input
end run
The latter choice can repeat not more than 1000 times.
I am trying to write some automation code (primarily in Ruby Selenium). At some point, a file chooser is opened in Safari so that the user can select a file for upload. Selenium cannot handle this, but I think AppleScript should be able to. I am new to AppleScript and haven't been able to find any boilerplate code of someone automating a file chooser dialog. I'm reading through the AppleScript docs, but any ideas would be most helpful.
Some more searching and I found a great answer here: Applescript file dialog with UI scripting
Here's what I ended up using:
on run argv
tell application "Safari"
activate
-- Usage check
set argc to count argv
if argc is not greater than 0 then
return "Usage: SafariFileChooser file_name [window_name]"
end if
-- The file we will choose to open
set file_name to item 1 of argv
-- Flip to the named window, if specified
if argc is equal to 2 then
set window_name to item 2 of argv
set flip_count to index of window window_name
repeat (flip_count - 1) times
activate
tell application "System Events" to keystroke "`" using command down
end repeat
end if
-- Interact with the dialog using System Events (thanks mcgrailm)
tell front window
activate
tell application "System Events"
keystroke "g" using {shift down, command down}
keystroke file_name
delay 1
keystroke return
delay 1
keystroke return
end tell
end tell
end tell
return 0
end run
Another option I just discovered is to specify the directory using the command-line:
do shell script "defaults write com.apple.Safari NSNavLastRootDirectory /path/to/directory"
This way you can do slightly less in UI scripting. Run this command before you open the file chooser, and it will put you into the directory specified. Include all the files you need in this directory, and you can just script command+a to select them all, and return.