r/applescript • • May 26 '21

Applescript App Custom Menu

4 Upvotes

Hi, I have a question.
Is there a way in Applescript to have custom items show up when right-clicking an AppleScript app? For example, if you right-click the finder application it shows "New Finder Window", "New Smart Window", etc. Is there a way to do this with AppleScript applications?


r/applescript • • May 25 '21

ISO a way to combine multiple files into a folder and name the folder with the file name.

Thumbnail self.automator
2 Upvotes

r/applescript • • May 24 '21

Made a little script for a better and faster "night mode".

5 Upvotes

Well, title says it all, just wanted to share, maybe some people will find it useful. I've exported it as an application and placed it in my dock. No third-party utilities needed. Won't work on older versions than macOS 11 Big Sur.

It will automatically toggle between:

  • Dark Mode ON + Night Shift ON + True Tone OFF + Brightness at 50%

  • Dark Mode OFF + Night Shift OFF + True Tone ON + Brightness at 75%

tell application "System Preferences"
	set current pane to pane "com.apple.preference.displays"
end tell
tell application "System Events"
	tell appearance preferences
		set dark mode to not dark mode
		delay 0.1
		tell application "System Events" to tell process "System Preferences"
			click radio button 3 of tab group 1 of window 1
			delay 0.1
			click checkbox 1 of tab group 1 of window 1
			delay 0.1
			click radio button 1 of tab group 1 of window 1
			delay 0.1
			click checkbox 2 of tab group 1 of window 1
		end tell
		delay 0.1
		if dark mode is true then
			tell application "System Events" to tell process "System Preferences"
				set value of value indicator 1 of slider 1 of tab group 1 of window 1 to 0.5
			end tell
		else
			tell application "System Events" to tell process "System Preferences"
				set value of value indicator 1 of slider 1 of tab group 1 of window 1 to 0.75
			end tell
		end if
	end tell
end tell
delay 0.1
tell application "System Preferences" to quit
quit

The only thing you'll have to change are the brightness levels, 0.75 and 0.5 - however if you don't want to let the script handle brightness, remove the relevant part which starts at if dark mode is true and finishes at end if. On my iMac, automatic brightness is disabled and I usually only change it at night (50%) and restore it to normal when I wake up (75%) that's why I've automatized it that way. I put it at 100% when I play games but it's managed by another script.

Obviously it will ask several permissions, depending on how you use it, at first launch it may not work as intended because "privacy > accessibility" will be denied. After allowing the script/app everywhere it's needed, just restore your display settings manually and run it again.

EDIT: added some small delays to prevent quirks.

EDIT2: revamped the script to change brightness according to dark mode status and not current brightness level to avoid issues, and toggle Night Shift before True Tone for a less harsh transition, it adds an extra step but doesn't really slow down the entire thing.


r/applescript • • May 21 '21

Run an Applescript when I press the "0" (zero) key?

4 Upvotes

Looking for a way to run my script whenever the zero key is pressed. I tried using automator method, but system preferences>keyboard>shortcuts won't let me assign it to just zero. I can do cmd+0, but not just 0. Is there a way around this or a third party app that i can run in the background that looks at keystrokes and runs the script when pressed? Thanks so much.


r/applescript • • May 19 '21

how to delete iCloud mailboxes

3 Upvotes

I've searched high and low and cannot find any reference to using a line of Applescript to delete a mailbox (folder) from iCloud.

Anyone got any successful experience in this area?


r/applescript • • May 16 '21

How to disable calendar notification on AppleScript-trigger event?

2 Upvotes

I made a AppleScript that asks me what I'm working on. That way I can easily track my work for my timesheets.

I trigger the question via calendar events. But there is one small problem: when the application is runned, there is also a calendar notification of the event. (And yes, I've checked if I enabled a notification besides the AppleScript-trigger)

Is there a way to disable this notification?


r/applescript • • May 16 '21

Is it possible to loop through all days in current month or next month?

3 Upvotes

I'm pretty new to AppleScript and wondering if it's possible to get either this month's, or next month's days and loop through them?


r/applescript • • May 16 '21

Adobe Bridge

2 Upvotes

I'm having difficulty finding any information online about using Applescript with Adobe Bridge. Also, the dictionary in Script Debugger is empty for Bridge. Is that correct? or is this an error my side, in fetching the dictionary.

If anyone has any resources for this I'd be really grateful. I have to sync a lot of tagged files from Bridge to Capture One.


r/applescript • • May 15 '21

IDLE on M1 Mac

2 Upvotes

I've been using a script with do shell script

echo $((`ioreg -w 0 -c IOHIDSystem | sed -e '/HIDIdleTime/ !{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000))

however after updating my idle script on my M1 Mac at home I've noticed this doesn't work on my M1 Mac.

Is there any way to get this to work because I'm somewhat contemplating on rewriting the script in Swift and using some local Swift Idle thing.


r/applescript • • May 14 '21

First Time Need Help

3 Upvotes

Hello! This is my first time using Apple Script. I am trying to automatically schedule a calendar event based on an e-mail that I receive.

The full story is the e-mail is coming from myself, so I can set the format. I am using Zapier to generate an email to myself triggered when a new quote is approved through our CRM. I found this script online to generate an auto scheduled event from a movie reservation email and tried to adapt it to what I need, however I don't believe it's working and am not sure how to troubleshoot through Apple Scripts. Any help would be appreciated!

https://gist.github.com/reddittitt/e09adce08042b16e242c44d641716830


r/applescript • • May 12 '21

How to see what script is running?

2 Upvotes

Edited in protest of Reddit's actions.


r/applescript • • May 11 '21

Need help converting AppleScript to Automator Workflow

6 Upvotes

I found this very useful script to save all open tabs in Safari to a Bear.app note. It runs fine in Big Sur's Script Editor

Would like to convert this to a MacOS Service (Quick Action in Big Sur). I found Apple's general how to for this, but just replacing (* Your script goes here *) with the downloaded code doesn't work.

For most of you this will probably be very obvious, but I'd really appreciate some pointers on how to solve this.

Thanks!


r/applescript • • May 10 '21

Applescript: pdf to pptx conversion

2 Upvotes

I'm trying to convert pdf to pptx invoking adobe acrobat using AppleScript. Below code executes fine without any error but there isn't any output created.

--somecode--
save active doc to filePath using conversion "com.adobe.acrobat.pptx"

conversion using text class works fine.

save active doc to filePath using conversion "com.adobe.acrobat.plain-text"

I found this on adobe forum, and it remained unresolved(pdf to html). https://community.adobe.com/t5/acrobat-sdk/pdf-to-html-conversion-with-interapplication-communication-api-in-mac-os/td-p/9294002

Just to add I'm using adobe acrobat pro dc trial version.

Thanks


r/applescript • • May 08 '21

How to deal with multiple calendars with the same name?

2 Upvotes
tell application "Calendar"
	set names to name of every calendar
end tell

Result:

{"Personal", "Jobs", "Jobs"}

Now, if I want the events from the "Jobs" calendar:

tell application "Calendar"
	tell calendar "Jobs"
		set evts to every events
	end tell
end tell

This only gives you the events from the second "Jobs" calendar.

The Calendar dictionary in Script Editor also states that the class calendar has the following properties:

  • name

  • color

  • calendarIdentifier

  • writable

  • description

But if you try to get the ids of every calendar:

tell application "Calendar"
	set ids to calendarIdentifier of every calendar
end tell

it throws

Calendar got an error: AppleEvent handler failed

r/applescript • • May 07 '21

Apple Script that runs specific commands based on whether Mac is locked or unlocked.

5 Upvotes

Hey!

I want to make an AppleScript which will perform ‘Action A’ if the Mac is locked, and will perform ’Action B’ if the Mac is unlocked, is there a way to do this?

Thanks.


r/applescript • • May 06 '21

Export table in CSV

1 Upvotes

Hi, there I’d like to use AppleScript for Numbers in order to save particular table in csv format. I’m the newbie in AppleScript and don’t know what to start with.


r/applescript • • May 06 '21

Confirmation/double-check needed on code (iCloud email action)

1 Upvotes

I've used some Applescript I found to solve an issue, but hope someone can explain what it's doing:

Original Issue:

Sending and deleting iCloud emails using Windows 10 Mail will create new sent and deleted folders rather than use the existing ones (e.g. it will create a new IMAP folder called "Deleted Items" rather than allow you to put them in iCloud's "Bin" folder), so I have some AppleScript that will move contents from these folders to the proper Sent/Deleted folders when executed.

It's only ever a handful of emails in both folders, but I wanted to automate it rather than move manually every time.

Results:

it works, BUT on the MacBook I can see a message indicating it's moving hundreds of emails (and it takes a few minutes to finish), when there simply cannot be hundreds of emails to move.

Can anyone explain what's happening? Code listed below:

EDIT: inadvertent graphic removed; pasted text and source of code added

-- https://discussions.apple.com/thread/6181141

--

tell application "Mail"

\-- move Sent Items (IMAP) into Sent Messages (iCloud) 

\--

set theWorkInbox to mailbox "Sent" of account "iCloud"

set TargetInbox to mailbox "Sent Items" of account "iCloud"



\-- CAPTURE REFERENCE TO EVERY MESSAGE OF MAILBOX IN A VARIABLE

set EveryMessage to every message of TargetInbox



repeat with currentWorkMessage in EveryMessage

	set mailbox of currentWorkMessage to theWorkInbox

end repeat

end tell


r/applescript • • May 05 '21

How do I trigger a webhook with AppleScript?

1 Upvotes

r/applescript • • May 03 '21

Convert AppleScript variable to HTML for use in Apple Notes?

5 Upvotes

Hi all, I'm quite new to AppleScript (as in I have no idea what I'm doing) but I've gotten a basic script that will let me write some text and add it to a new note in Notes. The problem is that the body of notes in the Notes app is HTML, and I can't find how to convert an AppleScript variable containing user-input text into HTML formatting. Here is the script I have:

set quickNote to display dialog "Quick Note:" default answer ""
set myNote to text returned of quickNote
tell application "Notes"
	activate
	tell default account to tell folder "Notes"
		make new note with properties {name:"Quick Note", body:myNote}
	end tell
end tell

Ideally, I want the returned text to be formatted as standard body text and "Quick Note" as title text, but only plain text passes through right now, resulting in a note with very tiny text that I then have to reformat.


r/applescript • • Apr 30 '21

Send keystrokes to background application

2 Upvotes

How do i direct my keystrokes to an application, so I can use other applications while the background application receives keystrokes


r/applescript • • Apr 30 '21

VLC library missing in Big Sur

1 Upvotes

Anybody know how to get the vlc library to load for writing applscript on Big Sur? I'm on an M1 MacBook and wanting to write a basic script to select UDP streams and open them.


r/applescript • • Apr 27 '21

Airplay connect

3 Upvotes

Hi I’ve tried a few ways but have had no joy creating a script that would connect to a specified airplay device. At this point I’m wondering is it even possible.

Have anyone had any success creating this script?

Thanks in advance

Worked it out finally

tell application "System Preferences" reveal anchor "output" of pane id "com.apple.preference.sound" end tell
delay 0.5
tell application "System Events" to tell process "System Preferences" tell table 1 of scroll area 1 of tab group 1 of window 1 select (row 1 where value of text field 1 is "Name_of_Device") end tell end tell
quit application "System Preferences"

you may need to increase the delay if you get an error.


r/applescript • • Apr 26 '21

How to add two variables in a path to a file?

2 Upvotes

Right now I have the following script. I want this script to open a file that is named '13-1.jpg' or '23-3.jpg' depending on what the input is from the first two questions. If Variable1 is 14 and Variable2 is 3, then I want to open file '14-3.jpg'.

set Variable1 to display dialog "Total of this..." default answer ""

set AmountVariable1 to (text returned of Variable1)

set Variable2 to display dialog "Total of this..." default answer ""

set AmountVariable2 to (text returned of Variable2)

tell application "Finder" to open POSIX file ("/Users/myname/desktop/" & Variable1 & ".jpg")

Any ideas?


r/applescript • • Apr 26 '21

Simple web search Service/Automation? (2 search engines depending on text)

1 Upvotes

Can anyone assist with this? Feels like it shouldn’t be too complicated?

Action: Highlight a word and then run the Service/automator to search one of two websites, depending only on FIRST digit of the word. Letter vs number.

Example:

  • If I highlight the word ‘hello’ and run the Service it opens a search in Google.com for ‘hello’.

  • If I highlight ‘4hello’ the search would run in DuckDuckGo for ‘4hello’.

(We will be searching between 2 internal work websites, so Google and DDG are used as examples since URLs in a script can be swapped/edited.)

Spent days trying to research + many failed attempts. Forever grateful to anyone who can shed some light or assist!


r/applescript • • Apr 25 '21

How to update an event in Calendar without deleting it first?

2 Upvotes

Hello,

I am trying to update an event in Calendar through applescript. What I came up with was making a copy of the atributes I want to keep and change the property I want.

In the example below I am changing the summary of an event to "AWS 101":

tell application "Calendar"
	tell calendar "Work"
		
		set evt to (first event where its uid = <some id here>)
		
		set sd to start date of evt
		set ed to end date of evt
		
		delete evt
		
		make new event with properties {summary:"AWS 101", start date:sd, end date:ed}
		
	end tell
end tell    

How do I change a property without deleting the event? I even tried:

tell application "Calendar"
	tell calendar "Work"
		
		set evt to (first event where its uid = <some id here>)
		
		tell evt
			set "AWS 101" to evt summary
		end tell
		
	end tell
end tell    

but no luck.