New answers tagged

1

Yes, it is simple and there is no need, in this case, to involve System Events. Just ask Notes directly if the window exists, e.g.: tell application "Notes" exists window "Notes" end tell This returns either true or false, however the code in this form may not be as useful as either wrapping the query in an if statement block or assigning the results ...


1

You can do this with the System Events application - for example: tell application "System Events" if exists (window "Terminal — -zsh" of process "Terminal") then display dialog "Found" else display dialog "Not found" end if end tell Note that process is case sensitive while window is not. Therefore this will work if exists (...


0

This following AppleScript code should work for you. Ultimately, this code sets a variable for the count of open documents in Pages (openDocuments) Then if the count of openDocuments is not 0, the names of the open documents are stored in this variable openDocumentNames if application "Pages" is not running then tell application "Pages" to activate ...


0

Please try this. It might run faster. (edited my original answer with new code). tell application "Finder" set theWindows to {} set theCount to (count of windows) if theCount is greater than 1 then repeat with i from 2 to theCount set theWindow to window i copy theWindow to end of theWindows end repeat ...


0

If you want to run this in Terminal you can use find /path/to/top/of/source -type f -iname '*.epub' -exec cp '{}' /path/to/target/ \; This will duplicate all files, which might be heavy on disk space depending on the number and size of your Epubs. You can also just link them by using find /path/to/top/of/source -type f -iname '*.epub' -exec ln '{}' /path/...


0

There are actually many different ways to do it in Automator! Here is one set of actions you could use: Ask For Finder Items Get Folder Contents Filter Finder Items Copy Finder Items


1

The perform action command is going to go the the frontmost window that meets the criteria of the the given command. As such, you need to use the activate command after tell application "iTerm" so win1 will be frontmost when the perform action command is triggered. tell application "iTerm" activate set win1 to (create window with default ...


0

Enabling the Reduce Motion setting in the Accessibility section of preferences will speed things up a bit. Hope this helps!


1

I do not know of a speed setting for this action. That said, the default setting for the Dock preference Minimize windows using: is Genie effect and the Scale effect may be a bit faster, so I'd try that one. There is also a Suck effect, which can be implemented via Terminal, using the following compound command: defaults write com.apple.dock mineffect -...


1

I just found the answer! You just need to drag the variable from the bottom of the screen into the desired text box.


1

Here is what worked for me: assuming that you grab input by having as a first line in your script the following: on run {input} Then you can perform within an iTerm window: write text "watch -n1 " & "'" & "kubectl get pods | grep -i " & input & "'"


1

Your run handler looks lifted from Automator, but your desire to have it as a script invoked from the shell suggests it's designed to be run independently of Automator. Here's an edited form of the script that you can copy and paste into a terminal (like iTerm): (:(){ paste - << SCRIPT > "$*" && chmod +x "$*" #!/usr/bin/env osascript on ...


1

Right after tell application "iTerm" add: if (window count) is equal to 0 then reopen This will open a new window if none are open but iTerm is running. You can also use the following example AppleScript code to make sure window 1 exists before continuing, if one wasn't already open. if (window count) is equal to 0 then reopen repeat until exists ...


1

If you are sure of the provenance of the AirDropped files and are happy to remove the quarantine extended attribute you can remove it as you say with xattr. In AppleScript you can do this using do shell script and passing the quoted path in alias form. removeQuarantine(quoted form of (POSIX path of (current_item as alias))) on removeQuarantine(...


1

This is a fairly simple if (running) quit, else launch structure. You'd have to leave the Script.app somewhere you can find it with the mouse, as KeyboardCleanTool will, of course, deactivate the keyboard input entirely if it is set to start cleaning mode automatically at launch. set appName to "KeyboardCleanTool" if application appName is running then ...


2

You would be best advised to either create the application from within Script Editor as an actual AppleScript app written in AppleScript; or to create an executable shell script program that is written in shell script without calling out to osascript. There's nothing wrong per se about mixing it up, and indeed there's lots of situations where it's needed or ...


2

The stream editor sed is likely the fastest and sharpest tool built for exactly this task. Use the insert command (the newline after \ is part of the syntax): sed 'i\ X' file > newfile $ time sed 'i\ X' line250000 >/dev/null real 0m0.118s user 0m0.102s sys 0m0.012s The delay or overhead for this operation is ...


9

To prepend X to the start of every line of file, writing to newfile, in Terminal: sed 's/^/X/' file > newfile Here I'm using sed, the Unix stream editor, to use a very simple regular expression to substitute the beginning of every line (the ^ symbol) with an X.


1

This bash snippet will prepend each line of a file with a hash (#) and save it to a new file: IFS=$'\r\n'; printf '#%s\n' $(</path/to/file.txt) > /path/to/newfile.txt Explanation IFS=$'\r\n': This sets the field separator so that only the characters \r (carriage return) and \n (newline) are used to delimit a string. The default setting can be ...


1

I think that got broken somewhere, as an alias is supposed to be a reference to a file item that remains valid even if it gets renamed or moved. If you are going to be using POSIX paths anyway, you might take a look at using Cocoa's NSURL class (via some AppleScriptObjC) to keep track of the file references, since that is ultimately what is getting used (or ...


10

Prepend each line of a file with a capital A and write a new file- awk '{print "A"$0}' < FILE > NEWFILE


1

To make an ApplesScript droplet app, save the following example AppleScript code in Script Editor as an application: on open droppedItems repeat with droppedItem in droppedItems do shell script "/usr/local/bin/exiftool -all= " & ¬ quoted form of POSIX path of droppedItem end repeat end open Now drag and drop the target file(...


1

That button is added to Finder using the FinderSync Extension APIs: https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/Finder.html Finder Sync supports apps that synchronize the contents of a local folder with a remote data source. It improves user experience by providing immediate visual feedback directly in the ...


2

receipt is an element belonging to some parent object. As with any instance of an AppleScript element that has already been created, it'll typically be referenced either by index, e.g. receipt 1 of ... or by name, e.g. receipt "MyNamedReceipt" of ... or by id, e.g. receipt id "61405882-ee27-4c94-86bb-bcdecc8792ba" of ... My feeling is that the add ...


1

Since you didn't say what version of macOS you are running, here is the AppleScript code I'd use to toggle the target checkbox under macOS High Sierra. It may need to be modified for macOS Mojave and later. Also note that when assigning a global keyboard shortcut, it can not be one already assigned to any app that has focus when the keyboard shortcut is ...


7

Prior to macOS Catalina the accept command was a symlink to cupsaccept. So in macOS Catalina, use: /usr/sbin/cupsaccept In macOS Mojave, in Terminal: $ which accept /usr/sbin/accept $ ls -l /usr/sbin/accept lrwxr-xr-x 1 root wheel 10 Sep 7 21:22 /usr/sbin/accept -> cupsaccept $ In macOS Catalina, in Terminal: % which cupsaccept /usr/sbin/...


3

The immediate solution would be to use the Replies pane rather than the Results pane in Script Editor. It will print a live result from each AppleScript command executed during the run of a script, whereas the Results pane only returns the overall result of the script's execution (which equates to the result of only the final command). The final command in ...


1

Try using the log() function, it will log the results to the messages pane. Example: set i to 1 repeat 10 times log (i) set i to i + 1 end repeat Make sure that you open up the messages pane: Edit: If it's important that it's only the returned value, than you could simply keep track of all the strings and add them together and return the ...


0

######################################## BASH LIB ####################################### bash.string.replace() { local text="$1" find="$2" replace="$3"; echo "${text}" | while IFS= read -r line; do printf '%s\n' "${line//"$find"/$replace}"; done } ######################################## BASH LIB ##################...


1

There is a much easier way to do this on the Mac: Keyboard Maestro. Despite the name, it automates the mouse as well as the keyboard. It let you use GUI tools to setup the clicks (all you have to go is tell it to watch where you click, then click, and it will do the calculation for you). It will let you set a specific delay between the clicks. It also ...


2

Why AppleScript or Automator when this can be done in just Terminal? Are all the files in the same folder? What type of file is been converted, its extension, e.g .mp4? If all the files are in the same folder and only the target files, then in Terminal, use to following commands: cd /path/to/target_files for f in *.*; do echo ffmpeg -i "$f" -ac 2 -codec:a ...


1

The following steps are a solution for automating the repeat clicking of a mouse, back and forth, at two different fixed positions within a web page -- i.e. clicking two buttons or links within in a web-page, with a user-defined delay between each click. All this is, is a slight modification of what was described over in this thread -- this one being for ...


0

@red_menace has provided an excellent answer and explanation. I would choose to script the closing of all notifications by targeting all of them at once in order to perform a single action. It would be more efficient than a repeat loop, and should therefore produce a swifter clearance with little or no stalling. use application id "com.apple.SystemEvents" ...


1

So glad you figured out your script! Just wanted to include that you also may be able to use Selenium to do this for you. https://www.seleniumhq.org/ Selenium is used by Quality Assurance professionals to automate the testing of websites, and is made to do everything a user would do and more. Here is an article that describes automating mouse clicks with ...


1

Well, many thanks to CJK for the explanations! After some struggle with Keyboard Maestro (because of how Boom is made, a Boom2device appears in the sound output devices and never really changes, so the trigger from Keyboard Maestro doesn't work...) I tried user3439894's solution and got Eventscripts to work in less than 10 minutes! The real plus with ...


0

When scripting the user interface, for things like windows and menus the object hierarchy usually doesn't exist until it is shown, so the object needs to be shown before trying to get its properties. Once the window or menu is shown, you can use the Accessibility Inspector tool (included in the Xcode bundle) or manually spelunk the various UI elements to ...


Top 50 recent answers are included