A simpler method of doing this is actually built right into macOS in the Keyboard preferences: http://osxdaily.com/2010/07/23/set-up-text-substitution-in-mac-os-x/
The bonus of this method is that your keyboard substitutions sync via iCloud to your iOS devices.
An alternative is to create an event listener and place the script in the scripts folder for a specific application: https://stackoverflow.com/questions/12023396/adding-an-event-listener-with-applescript
Edit: added bonus benefit
I would wrap a find bash script inside the AppleScript to do what you are doing:
Look here for syntax on find and excluding files/directories.
Full disclosure, I have never used ImageJ so all of what I am telling you is based on my quick (very quick) reading of the ImageJ documentation.
Near as I can tell you could create a macro to do what you want (see this documentation)
Then create a script in bash to run through all the files you need it to with the command line options sending the output to a CSV.
After years of using Automator to do things like this, I realized that Hazel is a much more powerful/convenient option than anything else. It’ll cost you but it will make your life better for years to come.
Try running this as a shell script or in terminal:
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -z
This article mentions how to do that in order to change a MAC address but should work for you as well.
I know that Things3 has limited AppleScript support, but most of their documentation is about getting things into Things, not out. I’d try https://culturedcode.com/things/download/Things3AppleScriptGuide.pdf to see what options exist.
Thank you.
Yes, this was two scripts mashed together. My hope exceeded reality.
I was taking http://osxdaily.com/2014/01/27/word-character-counter-service-mac-os-x/ and trying to use it with the Fleisch-Kincaid script that is meant to work with BBEdit from here: http://preserve.mactech.com/articles/mactech/Vol.24/24.08/ASBBEdit/index.html
Thanks for taking the time to answer in such detail.
That's why I didn't suggest this method. In my opinion it's way easier to just hold down shift :)
Here is how to do this task using the Saved Application States folder method.
>do shell script "/usr/local/bin/cliclick c:+0,+70"
Unfortunatly not. as far as I can see only this line can be changed
do shell script "/usr/local/bin/cliclick c:+0,+70"
in for instance
tell menu 1 of row targetrow of table 1 of scroll area 1 of window i of process "
<code>zoom.us</code>"
if exists menu item "Spotlight Video" the
click menu item "Spotlight Video"
else if exists menu item "Cancel the Spotlight Video" then
click menu item "Cancel the Spotlight Video"
else if exists menu item "Ask to Start Video" then
click menu item "Ask to Start Video"
else
key code 53
end if
end tell
Another improvement would be to check if the menu item "Spotlight Video" is available or not. That's not a problem since the menu "More" is available via
menu 1 of row targetrow of table 1 of scroll area 1 of window i of process "
<code>zoom.us</code>"
Your approach is all wrong.
You basically want to open a bunch of URLs in Google Chrome. So, to make it convenient, store the URLs in a plain text file, one URL per line, like this:
https://mail.google.com/mail/u/0/#inbox
https://calendar.google.com/calendar/u/0/r?pli=1" . . .
and so on.
Save the file as whatever you like, but for the purposes of this, I'm going to assume it's saved at ~/.chrome.URLs
where ~/
denotes your home folder, and I decided it might be an invisible file prefixed with a .
Here's how to open the URLs in Google Chrome using AppleScript:
set filename to ".chrome.URLs"
set URLs to read (system attribute "HOME") & ¬
"/" & the filename using delimiter linefeed
tell application id ("com.google.chrome" to tell ¬
(a reference to the front window) to if ¬
(it exists) or (exists (make new window)) ¬
then repeat with _url in URLs
make new tab with properties ¬
{URL:_url} at end of ¬
every tab in it
end repeat
Try this, it appears that applescript is trying to set the bounds of the window before chrome has finished reopening. Depending on your system, you may need to adjust the amount of delay. I have a pretty new machine that isn't bloated yet, so 1 second worked for me in a couple test runs.
tell application "Google Chrome"
if it is running then
quit
my openChrome()
else
my openChrome()
end if
end tell
on openChrome()
tell application "Google Chrome"
activate
--allow chrome to fully start
delay 1
set the bounds of the first window to {0, 0, 1300, 1600}
open location "https://mail.google.com/mail/u/0/#inbox"
open location "https://calendar.google.com/calendar/u/0/r?pli=1"
activate
--put focus on first tab
tell application "System Events"
keystroke "1" using command down
end tell
end tell
end openChrome
The dock preferences are in a .plist inside of Dock.app. My guess is that the script workflow will go something like this:
Replace existing dock .plist (containing whatever is currently on the dock) with a .plist populated with preset apps.
Kill/restart the dock.
Locations of Dock .plists are:
/System/Library/CoreServices/Dock.app/Contents/Resources/com.apple.dockfixup.plist /System/Library/CoreServices/Dock.app/Contents/Resources/en.lproj/default.plist
You should be able to populate your dock and then copy the .plist to a safe location for each of your individual contexts. Then it's just a matter of writing a script replacing the existing .plists with whichever one you want to use and then restarting the dock.
You could also just use Dock Spaces.
This is not doable with AppleScript at all. The APIs for this are unavailable, and you need to control the window server to manipulate spaces.
If you're good with the command line you can use yabai. The functionality to move spaces requires System Integrity Protection to be disabled, so yabai can take over Dock.app and control the window server.
The following script will do the job with a mix of yabai
and jq
, and I explained every step in detail.
#! /usr/bin/env zsh
# swap space 1 on display 1 with space 1 on display 2
# requires yabai and jq
# grab the index of the focused space
space1="$(yabai -m query --spaces --space | jq '.index')"
# grab the index of the first display
display1="$(yabai -m query --displays | jq ".[] | select(.spaces[] | contains(${space1}))")"
# create a temporary space to work on
yabai -m space --create
# focus the temporary space
yabai -m space --focus "$(yabai -m query --spaces --display | jq 'map(select(."native-fullscreen" == 0))[-1].index')"
# grab the index of the visible space on the other display
space2="$(yabai -m query --spaces | jq 'map(select(.focused == 0 and .visible == 1)).index')"
# grab the index of the other display
display2="$(yabai -m query --displays | jq ".[] | select(.spaces[] | contains(${space2}))")"
# move space1 to display2
yabai -m space "${space1}" --display "${display2}"
# move space2 to display 1
yabai -m space "${space2}" --display "${display1}"
# destroy the space we were temporarily working from
yabai -m space --destroy
Answering my own question - Yes, there are command line options.
http://rsbweb.nih.gov/ij/docs/guide/146-18.html
I suspect you could create a macro to do what you need to do and tell it to run from the command line appending the results to a CSV which can be read by excel.
Hazel may be useful for this. It is a third-party app that runs in the background and watches folders and runs rules on them when criteria are met. So for example, it can watch for new folders with the name "PDF[S]" and if it finds one run a terminal command to make a symbolic link:
ln -s /path/to/original /path/to/symlink
In Hazel lingo, the file that has "matched" is referred to as $1 so your code would look like:
ln -s /path/to/original $1
One way to set full screen is to use Applescript to emulate key codes. Check the correct keyboard shortcut for fullscreen for the specific applications from the applications' View menu. It's usually either cmd+F or control+cmd+F.
For snapping applications to occupy a specific area of the screen, there might actually now be a native way to do it too but I've always done it with the nice presets of BetterTouchTool which has been a necessary part of my workflows for almost a decade. So BetterTouchTool would perform that action upon some keyboard shortcut or other gesture of your choice as a trigger. Shortcuts can be global, or application-specific. It also has plenty of other actions, some of which involve window resizing/positioning.
In case triggering fn key with AppleScript proves difficult (I haven't tested it!):
Not an AppleScript, but just a tip that another good way to trigger a shortcut or a chain of them is to assign it with BetterTouchTool. The shortcut can be global or available for specific software only. Using BTT is extremely useful for much more than just this, which is why I even recommend this external solution; I've been using it for years and couldn't live without it anymore because I've set it to do so much stuff in all software contexts. It's set to trigger additional keyboard shortcuts, chains of events, and launch AppleScripts, most of the time.
Thanks for the suggestion! I tried it with the tell blocks separately and it (kinda) works. If I copy my password to the clipboard manually and run the script on the left, it connects like it should. If I run the script on the right, it doesn't. Could it have something to do with special characters in my password?
Hey there! I just joined r/applescript and I am glad that I found something to help with so quickly =)
So, what you will want to do is copy the Shazam string
("My discovery on Shazam: Joakim - Samurai (Meditation Tunnel Remix). https://www.shazam.com/track/347189649/samurai-meditation-tunnel-remix» to the «Joakim - Samurai (Meditation Tunnel Remix)" in your example)
and then run this script:
set the clipboard to (item 1 of splitText((item 2 of splitText(the clipboard, "Shazam: ")), ". http")) as string
on splitText(theString, theDelimiter) set oldDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to theDelimiter set theArray to every text item of theString set AppleScript's text item delimiters to oldDelimiters return theArray end splitText
The easiest thing to do would be to save this out as an AppleScript app using Script Editor and then add the app to your dock. Then you could copy your shazam string, click the app icon in your dock and when you paste, Presto! you have the output you're looking for.
Sorted! Issue resolved working code:
on run {input, parameters}
tell application "Safari"
open location "https://tinder.com"
delay 5
if (do JavaScript "document.readyState" in document 1) is "complete" then do JavaScript "var likeButton = document.querySelector('[aria-label=\"Like\"]');
function clickIt() {
likeButton.click()
}
var like = 1;
function likeProfiles() {
setTimeout(function() {
clickIt();
like++;
if (like < 100) {
likeProfiles();
}
},2000)
}
likeProfiles()" in document 1
end tell
return input
end run
I can write in AutoHotKey (close to what you have there for windows) and Applescript.
They are not interchangeable. You can not do what you are asking like you are asking to do with applescript.
You can do it with python wrapped in applescript.
You could do it with a 3rd party app: http://www.bluem.net/en/mac/cliclick/
but you'll need to learn how to do it.
Sorting is a lot of effort if all you want is the lower value of a thing. The latter is pretty easy, so I'll give you the lowest value:
Given an AppleScript list of records:
set JSON to {{content:"Try adding insurance to N26", |id|:3.154042165E+9, comment_count:0, label_ids:{}, |url|:"https://todoist.com/showTask?id=3154042165", completed:false, priority:1, order:1, created:"2019-04-16T10:35:56Z", project_id:2.209054284E+9, due:{|string|:"Jul 1", recurring:false, |date|:"2019-07-01"}, indent:1}, {content:..., ..., due:{...}, indent:...}, {...}, ...}
you can extract the content
property of the item with the earliest date stored in the property |date|
inside the record of the property due
like so:
tell (a reference to JSON) to repeat set |date| to item 1's due's |date| if |date| < item 2's due's |date| then set item 2 to item 1 set the contents to the rest if its length = 1 then exit repeat end repeat
return item 1's content in JSON
This obliterated the JSON
list as it goes, so if you wish you retain the information in the variable JSON
to make use of it later in your script just copy it to another variable.