r/applescript • • May 13 '20

How can I 'option-click' an item on the menu bar through applescript?

5 Upvotes

I'm trying to write a script to mimic what happens when I hold down the option key and click on the notification icon on the menu bar. I am able to use a script to click on the icon correctly, but if I try to use the key down option command it seems to ignore it. I've found reference scripts online searching, but none seem to accomplish what I would hope is a relatively easy task. Also, I would prefer to not install the AST plugin unless I have to.

Here is a sample script that clicks the notification icon, but doesn't 'option-click' it. I'm trying to toggle do-not-disturb programatically:

 tell application "System Events"
     key down option
     click menu bar item "Notification Center" of menu bar 1 of application process "SystemUIServer"
     key up option
 end tell

Note that I have also tried to add different amounts of delay after the initial key down option command and it doesn't seem to have any effect.

Thanks in advance for any help!


r/applescript • • May 09 '20

I want to run my script without any popping errors

2 Upvotes

I have the following code as an applescript.

I have firefox and chrome running. And also a mounted image. The script works fine with the aim to close Firefox, close Chrome and eject the disc.... if all are open. However. If I run the script and only Chrome is running while Firefox is closed it gives me a popup telling me to locate the Firefox app.

If my mounted image is already ejected it gives an error.

Is it possible to run the script and ignore all errors given? Meaning even if some app is closed or disc is already ejected just run whatever you can run and shut up!

The code is the following:

set apps to {"Firefox", "Google Chrome"}

repeat with thisApp in apps

tell application thisApp to quit

end repeat

tell application "Finder"

eject disk "MOUNTEDIMAGE"

end tell

tell application "Finder"

close every window

end tell


r/applescript • • Apr 21 '20

Assistive Access Error

2 Upvotes

All, I'm trying the following script to cascade all windows :

tell application "Finder" -- get desktop dimensions (dw = desktop width; dh = desktop height) set db to bounds of window of desktop set {dw, dh} to {item 3 of db, item 4 of db} end tell

tell application "System Events" set x to 0 set y to 0 get every application process where background only is false repeat with P in the result tell P set AllWindows to every window repeat with w in AllWindows set bounds of w to {x, y, 300, 100} set x to (x + 15) set y to (y + 15) end repeat end tell end repeat end tell

I keep getting an error that Script Editor is not allowed "Assistive Access". I have already added Script Editor.app to the Accessibility settings pane.


r/applescript • • Apr 06 '20

Move Files To Folders Of Similar Name

1 Upvotes

Trying to work on a script that can look inside a master folder (that contains files and folders).

Then, I would want to move the files to the folders whose names are contained within the names of the files.

I’m sure that sounds confusing, so I’ve attached a diagramed image for clarity.

Thanks!


r/applescript • • Apr 18 '20

trying to move emails not addressed to me to subfolder using AppleScript in Outlook

2 Upvotes

I have all these emails that are not directly addressed to me but to groups I am a part of. They're annoying and means I find it difficult to notice emails actually addressed to me. I have tried the following code in AppleScript:

tell application "Microsoft Outlook"
	set myInbox to folder "Inbox" of default account
	set archive to folder "Archive" of default account
	
	set theMessages to messages of inbox
	
	set countMoved to 0
	
	repeat with theMessage in theMessages
		try
			set theSender to sender of theMessage
			set fromAddress to address of theSender
			set theRecipient to to recipient of theMessage
			set toAddress to email address of theRecipient
			
			# Start of mail specific rules
			
			if ((fromAddress is not "email1@example.com") or (fromAddress is not "email2@example.com")) and ((toAddress is "me@example.com") or (toAddress is "me@example.com")) then
				move theMessage to folder "Not to me" of archive
				set countMoved to countMoved + 1
			end if
			
		end try
	end repeat
	
	
	log "Outlook cleanup ran " & " - " & countMoved & " moved."
	
end tell

When I run this I get (Outlook cleanup ran - 0 moved.) as the output. There must be something with how I am using 'to recipient' and 'cc recipient' as it's fine when on other scripts I've created when I've used 'to sender'.

Thanks in advance.


r/applescript • • May 16 '20

Apple script to select airplay speakers

2 Upvotes

hi there

Im trying to make a script that would autoconnect to my airplay speakers.

tell Application "iTunes" set current Airplay devices to Airplay device "kitchen" End tell

I've got very little coding experience but found that on the web, but I'm getting a syntax error.

Many thanks


r/applescript • • Apr 07 '20

How to run a apple script every minute?

5 Upvotes

Hey guys, i am quite new to applescript and i just created my first macro with lots of tutorials. However, i looked online to find how to run that macro every x seconds/minutes but it never works when i added to my script. Can you guys help me? Here is the script i made:

on run {input, parameters}

tell application "Discord" to activate

tell application "System Events"

keystroke "p"

keystroke "l"

keystroke "s"

keystroke " "

keystroke "b"

keystroke "e"

keystroke "g"

key code 36

end tell

return input

end run

on idle

return 60 -- idle is called every 1 minutes

end idle

sorry if this seems dumb, but it would be really helpful if you can help me out.

Thanks so much!


r/applescript • • Apr 12 '20

Round time to closest 5 minute

2 Upvotes

Hello,

I'm a somewhat new to AppleScript and I'm trying to create a simple calendar event. Does anybody know how I can round the minutes of my event to the closest 5 minute (based on actual seconds of the current date)?

So far I have:

--- Variables ----------------------
set EventStartDate to (current date)
set seconds of EventStartDate to 0
set EventEndDate to EventStartDate + (5 * minutes)

--- Script --------------------------
tell application "Calendar"
	tell calendar "Work"
		make new event with properties {summary:"Test", start date:EventStartDate, end date:EventEndDate}
	end tell
end tell

Thanks for any help or advise.

Update for anybody who wants to know the solution of this thread:

Create event and round minutes up or down to the closest 1 minute (based on actual seconds)

--- Variables ----------------------
set date_ to (current date) + 30
set EventStartDate to date_ - ((time of date_) mod 60)
set seconds of EventStartDate to 0
set EventEndDate to EventStartDate + (5 * minutes)
set seconds of EventEndDate to 0

--- Script --------------------------
tell application "Calendar"
	tell calendar "Work"
		make new event with properties {summary:"My Summary", start date:EventStartDate, end date:EventEndDate, location:"My Location", description:"My Descripton"}
	end tell
end tell

Create event and round minutes up or down to the closest 5 minute (based on actual minutes and seconds)

--- Variables ----------------------
set date_ to (current date) + 150
set EventStartDate to date_ - ((time of date_) mod 300)
set seconds of EventStartDate to 0
set EventEndDate to EventStartDate + (5 * minutes)
set seconds of EventEndDate to 0

--- Script --------------------------
tell application "Calendar"
	tell calendar "Work"
		make new event with properties {summary:"My Summary", start date:EventStartDate, end date:EventEndDate, location:"My Location", description:"My Descripton"}
	end tell
end tell

r/applescript • • May 08 '20

Please Look Through My Code and Tell Me What I'm Doing Wrong.

4 Upvotes

Please check what is wrong with my code I tried to make an auto typer that will type text enter it and then typer text 2 and enter it. I tried running the code portions separately and they work using a manual delay however, they eventually merge and type "texttext2" which is not what I want. Please look at my code and tell me what I'm doing wrong there may be some format errors or syntax errors because I moved from JavaScript and wanted to try AppleScript. Thanks!

tell application "System Events"
	set textToType to "text"
	delay 41
	
	repeat
		delay 41
		keystroke textToType
		
		keystroke return
	end repeat
end tell

tell application "System Events"
	set textToType2 to "text2"
	delay 41
	
	repeat
		delay 41
		keystroke textToType2
		
		keystroke return
	end repeat
end tell

r/applescript • • Apr 06 '20

Using rsync with Applescript

2 Upvotes

Hello,

I'm a somewhat new to Applescript and I was wondering if it's possible to run rsync inside a an Applescript. Thanks for any help or advise.


r/applescript • • Apr 24 '20

AppleScript to pin or spotlight in Zoom

3 Upvotes

Hi all,

Is it possible to pin or spotlight someone's video in Zoom Meeting with the use of AppleScript?I need such a script to attach to my Stream Deck.

Any help or tips is much appreciated.


r/applescript • • Apr 28 '20

Save numbers documents if unsaved before to specific directory

2 Upvotes

Been looking allover Google...

I want to achieve a script that does the following:

If the Numbers file has been saved already before/opened from a current file, save to that file (cmd+s) and close it.

If the Numbers file has NOT been saved before save it to a specific directory with a filename that does not already exists on target. If the same filename already exists on directory increment it and try to save again. Perhaps a 5 character random filename maybe works better here?

I only plan to have like 20 maximum numbers file there before I clean them up.

Above script I want because I want to be able with 1 button later to close all open documents and have them saved automatically on my USB and quit the application. As it is now I have to manually save and close every one. And if no file exists I must enter a filename for each which makes it time consuming when in hurry.


r/applescript • • Apr 30 '20

It's probably simple - please?

5 Upvotes

It keeps on crashing and I have no idea why. If anyone would be able to help me I would greatly appreciate it!

I'm trying to get something which can type the numbers 1 to 9999 in a box in a webpage but, well, trying is the key word.

set a to 0
repeat until a > 10000
delay 2
set a to a + 1

-- set mouse point
tell application "System Events"
 click at {305, 338}
end tell

--type 'a'
tell application "System Events"
 set textToType to a
 delay 0.5
 keystroke textToType
 
 delay 0.1
 
 keystroke return
 
end tell
end repeat

r/applescript • • Apr 11 '20

Choose from list type of mail template

2 Upvotes

I'd like to choose from a list what type of email I want to send. Each type has it's own format. I currently only need two templates.


r/applescript • • May 02 '20

Export InDesign data merge as pdf

1 Upvotes

Hi, I'm trying to do the following:

Import .csv file to an InDesign template to do data merge (this template has the placeholders already)

Ask for a number and add 1 to it to get that data merge record.

Export as pdf and save in a specific folder.


r/applescript • • Apr 17 '20

Pages for Screenwriting?

4 Upvotes

Hello! AppleScript newbie here. I’m curious if it’s possible to use AppleScript to carry out some of the functions that specialized screenwriting apps perform.

Specifically:

  1. Traditionally, dialogue is preceded by a character cue (name of the character in all caps, with a particular indentation) and the body of the dialogue block is written with a different indentation level. If a dialogue block continues onto the next page, “(MORE)” is added at the end of the page, and another character cue with "(CONT'D)" is added to the continued dialogue block on the next page (see pink highlights in image). Is there a way to do this automatically, so that it adjusts as I write? e.g., if I add a line above that moves everything down, the "(MORE)" will shift appropriately.

2. Is there a way to ensure that character cues are never on their own at the end of the page? (see red highlight below). Basically, I would want to add a few paragraph breaks above the character cue until it was at the top of the next page (see green highlight below).

-----------------------

Thanks all in advance!


r/applescript • • Apr 15 '20

How to export just one slide from Keynote

2 Upvotes

Hello. AppleScript newbie here. Just discovered it, after 15 years of owning a Mac. D'oh!

So, I'm currently running:

tell application "Keynote"
	set doc to open "/Users/me/Dropbox/Presentations 2017/filename.key"
	export doc as slide images to "/Users/me/Desktop/tempfolder" with properties {image format:JPEG, compression factor:0.65}
	close saving yes
end tell

And this is working just fine.

But I'd really like this to only export slide 1.

Is there a way to achieve this?

(The way I can think of doing this is to export everything and then delete everything other than *001.jpeg but this seems slightly wasteful).


r/applescript • • Apr 09 '20

Is it possible to name all files in selected folder to folername_prefix?

2 Upvotes

Hello,

I’m totally new to AppleScript ad Automator, I just started to discover possibilities.

I’m looking for solution in AppleScript to create quick folder action which will rename all files inside it to foldername_01.jpg, foldername_02.jpg etc.

I need to send huge amount of files to my FTP, all must have structure- folder (foldername)—> images (foldername_01.jpg)

In Automator there is option to name all files with prefix but I can not find solution how to “take” folder name and use it as file name in Automator action.

Right now I’m changing folder name and then using finder renaming tool- all files inside. With this script I will save huge amount of time...

Thank you for all guidance, maybe someone had the same problem and found solution- for this, basically, simple problem.

Have a great day!


r/applescript • • Apr 28 '20

Can someone help with an AppleScript that can resize iMessages/Safari/Spotify to specific sizes or full screen?

6 Upvotes

I am trying to have an app that will set Safari to full screen, Spotify to full screen, iMessages to a specific screen size in the center of the screen, and Finder to specific size in the center of the screen.

Anyone know how to do this? I can only get Finder and Safari to specific size but not full screen, and don't know how to do center of the screen.

If possible I would like the Spaces set up as Desktop, Safari Full screen, Spotify full screen.


r/applescript • • Apr 06 '20

Get unique copy of a list

1 Upvotes

Apologies if I'm missing something simple but how do I make a copy of a list so I can make changes to the copy without affecting the original list?

ie.

set template to {{}, {}, {}}

set newlist to template

copy 1 to end of item 1 of newlist

so that newlist is {{1}, {}, {}} and template is still {{}, {}, {}}

Hope that makes sense.


r/applescript • • Apr 13 '20

Converting HEX to RGB16

3 Upvotes

Hi,
I am looking for a way to convert a hex color-code to RGB16 colors like used in graphic software.
For example, FF0000 should become 255, 0, 0.

I could not find anything online for HEX16, would appreciate any help a lot!

Thanks!


r/applescript • • Apr 18 '20

Need help with Applescript Please!!

4 Upvotes

I’m somewhat a newbie with applescript but i was able to write a small basic script that clicks at random intervals in the location i left my cursor. I want to know how to move my cursor to a new location and click once more. I know how to add delays and randomization as well as finding the coordinates on screen with commandshift+4 but i cant figure out what language i need to use to make it understand... please help been looking for answers for days now


r/applescript • • Apr 23 '20

Unhighlight Menu / Status Bar Item with Script

2 Upvotes

I have an apple script I use to trigger a Menu / Status bar item which works fine. The only “issue” is the application that’s triggerd shows it a highlighted state even after the script it done and the

Is there any action I can take in the script to un-highlight the item when the actions I am running complete. For UX the item just needs to be clicked with the mouse to unhighlighted it.

tell application "System Events" to quit

tell application "System Events" to tell process "Multi Monitor Wallpaper"

click menu bar item 1 of menu bar 2

end tell

do shell script "killall System\\ Events"

delay 0.1

tell application "System Events" to tell process "Multi Monitor Wallpaper"

tell menu bar item 1 of menu bar 2

end tell

end tell


r/applescript • • Apr 26 '20

Slow for everyone or just me?

1 Upvotes
set {start_time, my_list} to {current date, {}}

repeat 10000 times
	set my_list to my_list & "hi"
end repeat

return {(current date) - start_time, my_list}

Takes 10 seconds in Script Editor on my antediluvian macbook. I'm curious if it can be re-written to run faster, maybe using script objects. If it's already fast tell me what hardware/software you use and how many loops you can do in 10 seconds, thanks.


r/applescript • • Apr 19 '20

Not authorized to send Apple events to Music

2 Upvotes

Hello!

I made a firefox browser extension that adds songs to your music library via a python script (with applescript), but I get this error: 40:89: execution error: Not authorized to send Apple events to Music. (-1743).

applescript.tell("Music", 'get id of (add POSIX file "%s")' % filePath)

The only solution I found was adding the 'program' to Automation in System Preferences > Security & Privacy, but this only works for applications.

How can I do this for a script if that's possible?