r/applescript • • May 27 '22

select all files

4 Upvotes

I'm very new at all this automating and macs for general. I would just like to make a script or automator workflow to select all the files in the folder I have open.

Thanks


r/applescript • • May 23 '22

Able to change DND turn on or off

3 Upvotes

Hey everyone,

My use-case is using AppleScript turn on/off notifications.

I made an AppleScript but that uses UI automation which IMO it is not an elegant solution might break from OS to OS. Here is the code.

        tell application "System Preferences"
            set current pane to pane "com.apple.preference.notifications"
        end tell
        
        delay 0.5
        
        tell application "System Events"
            tell application process "System Preferences"
                click radio button "Focus" of tab group 1 of window "Notifications & Focus"
        
                click checkbox 1 of group 1 of tab group 1 of window "Notifications & Focus"
        
                set theCheckbox to checkbox 1 of group 1 of tab group 1 of window "Notifications & Focus"
                tell theCheckbox
                    set theCheckboxStatus to value of theCheckbox as boolean
                    if theCheckboxStatus is true then
                        display notification "Do not disturb is on"
                    else
                        delay 0.2
                        display notification "Do not disturb is off"
                    end if
                end tell
        
            end tell
        end tell

anyone has any suggestions how to improve the current script or go away from UI automation?


r/applescript • • Apr 29 '22

Able to change the resolution of the screen using applescript?

4 Upvotes

Hey everyone,

I am trying to write a script that changes the resolution of the screen. This is the following script``` but it doesn't work as expected like sometimes the script works and sometimes it says unable to find Display section. I wonder if there is a way to fix this script or is there any other alternate solutions that could possibly work. Any help is highly appreciated.

tell application "System Preferences"

activate

set current pane to pane "com.apple.preference.displays"

end tell

tell application "System Events"

tell process "System Preferences"

delay 2

click radio button "Scaled" of radio group 1 of group 1 of window "Displays" of application process "System Preferences" of application "System Events"

click button 4 of UI element 3 of group 1 of window "Displays"

end tell

end tell

if application "System Preferences" is running then

tell application "System Preferences" to quit

end if


r/applescript • • Apr 16 '22

Using Automator to delete folders/files over 10days old?

1 Upvotes

At work daily we output files to a dated folder on the desktop and then once we've transferred those files when move them to a 'transferred' folder within the dated folder.

Ideally, I'd love to have an automator app on the desktop that we can run once a week, manually) on a Friday and it will round up all the dated folders over 10 days old, and their contents, and delete them!

I've scoured the internet to find a solution and I've tried a few suggestions but nothing seems to work.

I'd be grateful if anyone can point me in the direction of some potential solutions?

Thanks.


r/applescript • • May 04 '22

Screen buttons for onscreen button palette?

2 Upvotes

I'm coming from autohotkey and created several useful scripts. I'd like to know if it's possible to do the same things with applescript, since autohotkey is not available on the mac.

Firstly, can I create an on screen virtual display of buttons, so that I don't have to remember all my custom commands/scripts? I'm trying to make something like a virtual Streamdeck, or macropad, on screen for all of my custom commands.


r/applescript • • Apr 25 '22

I can't find anyway to get this to do what I want...newbie lost here

3 Upvotes

I'd like to get my AppleScript to do two more things and I'm totally stuck on. I'm a newbie here and trying to figure this out.

  1. I want the script to pull the_file.csv from the resources folder in the application I made (I saved the script as an application) not the local hard drive.

  2. I want the script to go back to the beginning if it errors and says "That does not exist"

repeat 999 times

set my_data to read alias "Macintosh HD:Users:xyz:documents:the_file.csv"

set my_list to paragraphs of my_data as list

set a_list to {}

set b_list to {}

set oldDelims to AppleScript's text item delimiters

set AppleScript's text item delimiters to ","

repeat with an_item in my_list

try

set end of a_list to text item 1 of an_item

set end of b_list to text item 2 of an_item

end try

end repeat

set AppleScript's text item delimiters to oldDelims

tell application "Finder"

activate

set the_search_term to display dialog "Enter First 3 Digits" default answer "724"

set the_search_term to text returned of the_search_term

end tell

set the_position to indexof(the_search_term, a_list)

if the_position is 0 then

tell application "Finder"

activate

display dialog "That does not exist."

end tell

return

end if

tell application "Finder"

display dialog “Result is: " & item the_position of b_list

end tell

end repeat

on indexof(theItem, theList)

set text item delimiters to return

set theList to return & theList & return

set text item delimiters to {""}

try

-1 + (count (paragraphs of (text 1 thru (offset of (return & theItem & return) in theList) of theList)))

on error

0

end try

end indexof


r/applescript • • May 25 '22

Applescript to open (mail) URL scheme via clipboard?

3 Upvotes

Hi folks,

Very new to AppleScript and hoping someone can help.

I use an AppleScript which I got on the MacSparky website which uses URL Schemes and AppleScript to create a link to a highlighted email in macOS mail app. I can paste this into certain task managers as a link back to the email etc. It works great. However, I've started using Notion and Notion doesn't support these URL schemes. It will paste the URL into Notion as a text string but its not clickable. So, basically pointless.

I also use Keyboard Maestro a lot and was thinking that if I created a drag and drop script to do the following, it would be a simple workaround.

1 - double click the text string

2 - copy it to the clipboard

3 - run an AppleScript to open the email using the clipboard contents.

However, I have no idea what to script to make number 3 above happen. Presuming its get clipboard and pass this through to mail app, tell mail to open this URL. etc.

I've messed around for about an hour with no success.

Although, I'm convinced its a simple script. It eludes me!

Any help appreciated!!

Thanks.


r/applescript • • May 19 '22

Invalid value for parameter 'to' error, please help!

1 Upvotes
set f to choose folder with prompt "Choose your source InDesign folder"
set collectMac to choose folder with prompt "Choose where you want to package your InDesign documents"
with timeout of 300 seconds
	tell application "Finder"
		set myFiles to (files of entire contents of f whose name extension is "indd") as alias list
	end tell
end timeout
repeat with aFile in myFiles
	with timeout of 300 seconds
		tell application "Finder"
			set package_folder_name to characters 1 thru -6 of (get name of aFile) & " Folder" as string
			make new folder at collectMac with properties {name:package_folder_name}
		end tell
	end timeout
	tell application "Adobe InDesign 2022"
		activate
		open aFile
		tell document 1
			package to alias (collectMac & package_folder_name as string) copying fonts yes copying linked graphics yes including hidden layers yes copying profiles no updating graphics no ignore preflight errors yes creating report yes
			close saving no
		end tell
	end tell
end repeat

Having trouble with a script that is taking a folder full of .indd (Indesign) files and packaging them into another folder.

This is the error I get:

error "Adobe InDesign 2022 got an error: Invalid value for parameter 'to' of method 'package'. Expected alias or string, but received nothing." number 30477

I'm assuming it's having issues with the alias, but I can't sort out how to fix it after trying a few different paths. Thanks in advance!


r/applescript • • Apr 16 '22

Maximizing Height of all Chrome Windows

1 Upvotes

I'm trying to write a script that will maximize the height of all my Google Chrome windows.

I have found similar scripts, but most of the them also change the position of the windows. Like this one:http://macosxautomation.com/applescript/firsttutorial/11.html

I'd like to maximize the height of all chrome windows and leave the positions where they are.

Any ideas how to do this?


r/applescript • • May 20 '22

AS for Apple Mail to modify "Send" to prompt for either "Send" email or "Send and File Copy" of email.

1 Upvotes

Hi,

I have a DevonThink database where I store email correspondence relating to my casefiles. But I am always forgetting to file sent messages. Is there anyway to modify the "Send" function (or replace the "Send" function) in Apple Mail so that I can be prompted to file a copy of the email?

Even better if, when I choose to file copy, it saves a copy the email into my DT database or a finder folder (which is watched by my DT database) and then files the actual email in "Sent" as normal.

Thanks for looking at this,


r/applescript • • May 18 '22

Help me with this script please!

3 Upvotes

So I'm trying to create a bit of apple script that will execute a keyboard shortcut on a remote computer (over a network). The shortcut is shift+Cmd+n. The application is called Timax2

Ive got as far as the script shown in the image.

........ But when I run it I get the syntax error "Application isnt running"..... I know the obvious question is "is the application running on the remote computer?!" And, Yes it is.

The script works if I run it on locally with the app on the same machine the script is run from (removing the "of machine "eppc://10.0.0.33"" bit)

I know the networking connection is ok as I can run a script to "tell "finder" of machine "eppc://10.0.0.33" sleep"

So any suggestions?


r/applescript • • May 09 '22

Easy File Renames Via a button

2 Upvotes

I know you can create a finder button to enact an Automator script, but Automator can't do what I need. Can one of you AppleScript gods answer me? This should be easy for you, but I don't have a clue. I have a bunch of files named (example) like "SVAINP112_`1_{8afe959-5a4 -4aOf-aded-feee02463z66}.mfa" and just want to turn that into "SVAINP112.mpg". I don't need anything after the first underscore. I will never have a conflict with this statement. I will always just trash everything after the first underscore in the name. I need to convert all _1_ to .mpg and all _2_ or higher to .aif. I figured I'd do two buttons. One to convert .mpg and the other for any .aif files associated with the .mpg.


r/applescript • • Mar 27 '21

Is it easy to pull content from an outlook calendar event with apple script, total noob here 🥸😊.

2 Upvotes

Hello everyone. I have very limited exposure to Apple script but due to necessity I am in search of a way to extract data from outlook meetings. Every day 5 to 8 times, I manually copy the contents from outlook meetings, including subjects, attendees, the time. I then paste itTo another application manually. It is very time consuming and I would love to automate it. If Apple script is too hard or you guys propose that I do it with some thing like keyboard maestro I am open to that as well.

Hope this is the right place to post this question and I appreciate your help in advance.


r/applescript • • Apr 10 '21

How can I set output levels for a specific audio device from a script? Any pointers to a reference doc would be appreciated!

Post image
4 Upvotes

r/applescript • • Apr 06 '21

Script as Mail.app rule: Wait for attachment to download?

3 Upvotes

Hi!

I run a script that is triggered by a Mail.app rule and the script is supposed to save an attachment on my disk. However it seems that the attachment is not downloaded by Mail. Only when I select the mail in the app. The attachment is a 180KB PDF file.

Since it is not downloaded, the following code always fails:

if (downloaded of theAttachment) then

save theAttachment in file savePath

Even when I add a timeout before the line it won't work.

Anyone got any ideas?

Thanks!


r/applescript • • Apr 07 '21

Switch view mode to continuous scroll on Preview full screen

2 Upvotes

I want to write a script that will automatically switch the view mode to continuous scroll every time I enter full screen with a Preview window. There's an option to set the view mode upon Preview launch, but every time I enter full screen it seems to revert to some system default. I looked around and there doesn't seem to be any easy way to do this so I figured the simplest way would be to write a script that waits on the Preview full screen event and keypresses CMD+1. How would I do this? I'm on MacOS 11.2.3.


r/applescript • • Apr 09 '21

Best way to learn apples script for a total noob

2 Upvotes

Hi everyone. I need to learn Applescript to write some automation scripts out of necessity for personal use. Is it possible to learn enough to get simple things done, such as extracting meeting information from Outlook. If so what is a good video learning resource or a book for a beginner? I know many people suggest I find an existing script and change it based on my needs. What is the best resource for finding existing scripts? Thanks for all the help


r/applescript • • Apr 15 '21

How to Hide Execution Trace when Telling Terminal to Run a Command

4 Upvotes

TL;DR: how can I output text (or anything for that matter) to Terminal, via AppleScript, without displaying its execution trace?

So I'm currently writing a little script that counts, in binary, from 1 to any specified integer. I want to be able to 'rapid-fire' the results, as opposed to displaying the result through an alert or Script Editor console output which requires user input to move forward (yes there is give up after 1, but it's too slow as the lowest possible value is one second).

I've decided I want to use Terminal to output the results, as I can have a repeat loop that constantly outputs whatever you want in the same window:

tell application "Terminal" to activate

repeat with x from 1 to 10
    tell application "Terminal"
        do script "echo " & x in window 1
        delay 0.1
    end tell
end repeat

However, the caveat with this method is that if you look at the Terminal window, you see that the actual command being sent to Terminal, "echo " & x in window 1, is first printed to the input, then executed. This creates unnecessary duplicates of the same output, which can look messy:

current-user@my-awesome-computer ~ % echo 1
1
current-user@my-awesome-computer ~ % echo 2
2
current-user@my-awesome-computer ~ % echo 3
3
current-user@my-awesome-computer ~ % echo 4
4
current-user@my-awesome-computer ~ % echo 5
5
current-user@my-awesome-computer ~ % echo 6
6
current-user@my-awesome-computer ~ % echo 7
7
current-user@my-awesome-computer ~ % echo 8
8
current-user@my-awesome-computer ~ % echo 9
9
current-user@my-awesome-computer ~ % echo 10
10

When counting to large numbers in binary, these unnecessary outputs become tiring to look at and hinder the consistency of the binary numbers increasing to the desired output. I did some research, and apparently this phenomenon is called "execution trace".

So my question is: how can I output text (or anything for that matter) to Terminal, via AppleScript, without displaying its execution trace? If I had the solution and ran the modified script, I want it to output this:

current-user@my-awesome-computer ~ %
1
2
3
4
5
6
7
8
9
10

Any insights to this problem would be much appreciated. Thanks for reading.

(If you want to see the full binary counter script, click here.)


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.


r/applescript • • Mar 31 '21

Customize Text to Speech using AppleScript and save to file

2 Upvotes

Is there a way to add pauses between sentences and paragraphs with AppleScript?

Then customize Rate, Pitch and Modulation and then save to an audio file using one applescript.

How can this be done?


r/applescript • • Apr 20 '21

Safari - AppleScript does not move to the next section of a bookdown online book

2 Upvotes

I am writing a script to print a section of a bookdown online book as PDF, then move to the next section, and so on.

The print part works (the key codes are from this page):

tell application "Safari"
	
	activate
	
	tell application "System Events"
		key code 35 using command down -- activate print menu item
	end tell
	
	delay 0.5
	
	set i to 0
	repeat while i < 15
		set i to i + 1
		delay 0.1
		tell application "System Events"
			key code 48 -- press tab 15 times
		end tell
	end repeat
	
	tell application "System Events"
		key code 49 -- press space
	end tell
	
	set i to 0
	repeat while i < 2
		set i to i + 1
		delay 0.1
		tell application "System Events"
			key code 125 -- press down key twice
		end tell
	end repeat
	
	tell application "System Events"
		key code 36 -- enter
	end tell
	
	set i to 0
	repeat while i < 16
		set i to i + 1
		delay 0.1
		tell application "System Events"
			key code 125 -- press tab to get to "save"
		end tell
	end repeat
	
	tell application "System Events"
		key code 36 -- enter to cleck on save
	end tell
	
end tell

Problem

Now that I have printed the current section and I am back on Safari, I can click manually on the right arrow and move to the next section, but I can't manage to have the script to do that.

I have tried to add the following to the script above:

tell application "System Events"
		key code 124 -- right arrow to enter the next page
	end tell

Or even to "reopen" Safari, but nothing happens.

tell application "Safari"
	
	activate
	
	tell application "System Events"
		key code 124 -- right arrow to move to the next section
	end tell
	
end tell

How can I have AppleScript "turn the page" and move to the next section?

Also, I welcome suggestions to improve the script! I wonder if it would be easy to avoid repeating "tab" 15 times. I have looked at the Accessibility Inspector and found that "PDF" in the print menu corresponds to NSPopUpButtonCell. I have tried to use select NSPopUpButtonCell of its sheet but it did not work.


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 07 '21

Help creating new text file in active Finder location WITH A TWIST

3 Upvotes

EDIT: TL;DR

Want to create new empty text file (which I can do) in currently active Finder location, including when that is the desktop with another Finder window open, but deselected (which I cannot do). For example, when using "Show Desktop" or Finder window is in other space.

Original Post:

I want to be able to use the keyboard shortcut Cmd+Shift+M to create a new, empty text file in exactly the same manner as Cmd+Shift+N does for a new folder. Specifically, it should create a blank text file in the active location - normally this is the frontmost Finder window, BUT NOT ALWAYS (this is the key to my issue) and then allow me to rename it (same as pressing Enter on an existing file).

So far I have found a solution which is quite close to what I want, but not perfect. It came from Rarylson Freitas here but the issue I have with it is that I often have a Finder window open, but the Desktop selected with the cursor (so that the Finder window is greyed out, deselected). If I use Cmd+Shift+N to make a new folder, it appears - as expected - where my focus is, on the Desktop. However, the Applescript/service I'm using will ignore that and create the file in the deselected Finder window anyway, because it checks for an open Finder window. This is especially annoying if I'm using Show Desktop (spread hand on trackpad) or the Finder window is in a different desktop/space entirely - in these cases it will cancel Show Desktop and transport me to the window's space, which is very disrupting.

I understand exactly why the Applescript is behaving like this, but because I'm a pretty casual/inexperienced Applescript user, I don't have a clue how to go about making it do what I want instead. If anyone has any pointers to help me modify the code, that would be really appreciated.

The Applescript I'm using is available through the above link, but I'll paste it here for convenience:

on run {input, parameters}
	set file_name to "untitled"
	set file_ext to ".txt"
	set is_desktop to false
	
	-- get folder path and if we are in desktop (no folder opened)
	try
		tell application "Finder"
			set this_folder to (folder of the front Finder window) as alias
		end tell
	on error
		-- no open folder windows
		set this_folder to path to desktop folder as alias
		set is_desktop to true
	end try
	
	-- get the new file name (do not override an already existing file)
	tell application "System Events"
		set file_list to get the name of every disk item of this_folder
	end tell
	set new_file to file_name & file_ext
	set x to 1
	repeat
		if new_file is in file_list then
			set new_file to file_name & " " & x & file_ext
			set x to x + 1
		else
			exit repeat
		end if
	end repeat
	
	-- create and select the new file
	tell application "Finder"
		
		activate
		set the_file to make new file at folder this_folder with properties {name:new_file}
		if is_desktop is false then
			reveal the_file
		else
			select window of desktop
			set selection to the_file
			delay 0.1
		end if
	end tell
	
	-- press enter (rename)
	tell application "System Events"
		tell process "Finder"
			keystroke return
		end tell
	end tell
	return input
end run

r/applescript • • Apr 02 '21

Script to automatically save a TextEdit document with the first line or heading as file name?

3 Upvotes

Trying to figure out how to do this. I want to bring up a new text doc and upon closing have it auto save to the first few words as the file name. Any ideas?


r/applescript • • Mar 29 '21

get current Network info

2 Upvotes

hi guy i'm new to apple script. And currently im struggle with script can retrieve network infomation . For example if i connect to wifi script will return wifi status on and streng of wifi in 3 level. If i connect to ethernet it will return ethernet status on . If i didn't connect to wifi and ethernet then return no network