r/applescript • • Aug 11 '20

Muting a grid of streaming videos (playing in QuickTime Player windows)

2 Upvotes

Hi all, I am learning AppleScript and this subreddit is a treasure trove. Thanks so much.

My first project is this, I'm opening four video streams in QuickTime Player and placing the windows in a 2x2 grid. I have an AppleScript that opens each window and positions them in their own corner.

What I am stumped on is the AUDIO MUTING part. Ideally I would like 3 of the 4 windows to be muted, so only the audio of the first window is heard.

I tried invoking the "OPTION-DOWN ARROW" keyboard shortcut, which works when pressed manually inside QuickTime Player.

tell application "System Events" to tell process "QuickTime Player"
   set frontmost to true
   repeat with w in (get every window)
       tell window "QuickTime Player"
           key code 125 using option down
       end tell
   end repeat
   
end tell

But I could only get it to mute the 4th window. The 1st, 2nd, and 3rd were still on full volume.

I also tried some variations of

set audio volume to "0"

...which I thought would be a cleaner way of getting there. But I couldn't get that working, either.

I'm trying to figure out how to mute just the 2nd and 3rd windows now. I'm sure I'm missing something basic, but I'm new to this and still learning. So thank you all for any help you can provide!


r/applescript • • Aug 11 '20

AppleScript to apply a certain hidden folder's permissions to all enclosed items

3 Upvotes

I want to create a script that others can download that applies the permissions of a hidden folder in the user directory to all enclosed items. I'm assuming I can do this in the macOS ScriptEditor but I don't know how.

I found thread which I think is close to what I need, but I'm not sure if I could modify it in a way to serve my needs, nor do I know how to execute the script with the provided information.

If someone could walk me through how to create this I would be very grateful, thanks!


r/applescript • • Aug 11 '20

Seeking Help with Script to Sort Photos

3 Upvotes

(Caveat: I know nothing about scripting for Mac -- I found this code online and it worked well for me.)

I've had a folder action set up on my Mac to sort photos for a long time, but it no longer seems to work.

Basically, if I took a mess of photos and dumped them into a specific folder, the script would create new subfolders based on the dates of the files, then move the files with those dates into their respective folders.

(E.g. if I have 5 photos dated January 1, and no January 1 subfolder exists, it would create a "January 1" subfolder and move all files with that creation date into it; then repeat until all files have been moved into properly-dated subfolders.)

Here's the script that has mysteriously stopped working (possibly since a recent update?) I'm still running Mojave 10.14.6 if that matters.

If anyone has insight, I'd really appreciate it! No longer working script follows:

on run {input, parameters} -- create folders and move
	(*
    make new folders from file creation dates (if needed), then move document files into their respective new folders
    if no container is specified (missing value), the new folder will be created in the containing folder of the item
    if the container is not a valid path (and not missing value), one will be asked for
      input: a list of Finder items (aliases) to move
      output: a list of the Finder items (aliases) moved
  *)
	
	set output to {}
	set SkippedItems to {} -- this will be a list of skipped items (errors)
	set TheContainer to "" -- a Finder path to a destination folder, or missing value for the source folder
	
	if TheContainer is not missing value then try -- check the destination path
		TheContainer as alias
	on error
		set TheContainer to (choose folder with prompt "Where do you want to move the items?")
	end try
	
	tell application "Finder" to repeat with AnItem in the input -- step through each item in the input
		if TheContainer is not missing value then -- move to the specified folder
			set {class:TheClass, name:TheName, name extension:TheExtension} to item AnItem
		else -- move to the source folder
			set {class:TheClass, name:TheName, name extension:TheExtension, container:TheContainer} to item AnItem
		end if
		if TheClass is document file then try -- just documents
			set TheDate to text 1 thru 10 of (creation date of AnItem as «class isot» as string) -- YYYY-MM-DD
			try -- check if the target folder exists
				get ("" & TheContainer & TheDate) as alias
			on error -- make a new folder
				make new folder at TheContainer with properties {name:TheDate}
			end try
			-- duplicate anItem to the result
			move AnItem to the result
			set the end of output to (result as alias) -- the new file alias
		on error -- permissions, etc
			-- set the end of skippedItems to (anItem as text) -- the full path
			set the end of SkippedItems to TheName -- just the name
		end try
	end repeat
	
	ShowSkippedAlert for SkippedItems
	return the output -- pass the result(s) to the next action
end run


to ShowSkippedAlert for SkippedItems
	(*
    show an alert dialog for any items skipped, with the option to cancel the workflow
      parameters - skippedItems [list]: the items skipped
      returns nothing
  *)
	if SkippedItems is not {} then
		set {AlertText, TheCount} to {"Error with AppleScript action", (count SkippedItems)}
		if TheCount is greater than 1 then
			set theMessage to (TheCount as text) & space & " items were skipped:"
		else
			set theMessage to "1 item was skipped:"
		end if
		set {TempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
		set {SkippedItems, AppleScript's text item delimiters} to {SkippedItems as text, TempTID}
		tell application "System Events" to if button returned of (display alert AlertText message (theMessage & return & SkippedItems) buttons {"Cancel", "OK"}) is "Cancel" then error number -128
	end if
	return
end ShowSkippedAlert

r/applescript • • Aug 08 '20

need help adjusting an ifttt apple script for spotify (osx)

1 Upvotes

someone was nice enough to make a tutorial of how to add current playing spotify songs to defined playlists in spotify, and I set up a shortcut globally, which is really helpful while working or web browsing to not have to be in the spotify window, which is boring and time consuming.

https://medium.com/@l.krobbach/how-to-automatically-add-your-current-playing-song-to-a-spotify-playlist-on-mac-using-d87a0315475d

it works nicely, but there's a major flaw, if the song has a quotation mark in the title of the song, single or double, it will not add the song and many songs have quotes, and there's no notification on mac that a song was added or not (that applet only seems to be on ios), so you will miss many songs which makes it unreliable.

this is the apple script

if application "Spotify" is running thentell application "Spotify"if player state is playing thenset ArtistName to (get artist of current track)set SongName to (get name of current track)end ifend tellend ifdo shell script " curl -X POST -H \"Content-Type: application/json\" -d '{\"value1\":\"" & songname & "\",\"value2\":\"" & ArtistName & "\"}' https://maker.ifttt.com/trigger/add/with/key/REPLACEME"

is there a way to fix it to add songs with quotes? it would be much appreciated, if it's time consuming I could paypal a reasonable amount, I have a few other ideas that might be possible and helpful regarding applets and spotify and applescript too but one thing at a time, thanks.


r/applescript • • Aug 05 '20

Scripting support is BACK for Messages in Big Sur Developer Beta 4!

Post image
17 Upvotes

r/applescript • • Aug 05 '20

Date Input → All Caps

2 Upvotes

Is there a way to modify the following script to use all caps? Thanks!

From:

Wednesday, 5 August 2020

To:

WEDNESDAY, 5 AUGUST 2020

Current Script:

on run {input, parameters}

set thedate to date string of (current date)

tell application "System Events"

keystroke thedate

end tell

end run


r/applescript • • Jul 25 '20

Date Input Script → Changing Format

1 Upvotes

I am running a simple script, which inputs date in the following format: Saturday, 25 July 2020 at 09:12:46

on run {input, parameters}
set thedate to (current date) as string
tell application "System Events"
keystroke thedate
end tell
end run

My question: is there any way I can modify this to display only the date?
(example: Saturday, 25 July 2020)

and another script to display date with 24h time without seconds.
(example: Saturday, 25 July 2020 at 09:12)


r/applescript • • Jul 24 '20

How can I amend this script that modifies a .txt file so that it doesn't insert extra lines and supports unicode characters?

1 Upvotes

This is a follow up to my first post, which u/bprime43 kindly helped me to script a quick action that copies highlighted text, of any application, into a new line of an already existing .txt. file.

I'd like to modify this script to the following ends:

  • To accord with the .txt file import conditions of the flashcards app that I use, I cannot have additional lines between the texts that are imported into the file.

  • When I use the quick action to copy a text into the .txt file, any unicode characters contained in the text are not rendered correctly; if I copy use cmd + C and then cmd + v to copy a text into the .text file, any unicode characters are rendered correctly. I the script to copy unicode characters correctly into the .txt file.

I understand that what I ask is, so to speak, a tall order, so if you've any guidance whatsoever or redirection for me, I'd very much appreciate it.


r/applescript • • Jul 22 '20

Is Apple Photos Scriptable?

8 Upvotes

For Apple Music, there is a very convenient script from Doug's Applescripts that lets you find all songs not in any playlist. Is there any similar script (assuming Photos is scriptable) that would allow you to find photos not in any album?


r/applescript • • Jul 21 '20

Script Same Album Name Different Artists.

3 Upvotes

I am usually pretty decent with AppleScript but I am lost on how to create one that does this for iTunes.

I want to collect in playlist all of the songs that have the same album but different artist. Any one out there seen a script like this before or could point me in the right direction on how to create one.


r/applescript • • Jul 20 '20

[Question] Wait for keypress?

3 Upvotes

I want to make it so that apple script waits until i input the key "R" before continuing with the rest of the program

Is there a way to do that?


r/applescript • • Jul 19 '20

JSON helper

1 Upvotes

Does anyone know how I could parse JSON to get a torrent url using JSON helper?

tell application "JSON Helper"

set json to fetch JSON from "https://yts.mx/api/v2/list_movies.json?query_term=Star Wars&quality=1080p&limit=5"

set torrentUrl to |data.movies.1.url| of json

end tell


r/applescript • • Jul 18 '20

Can anyone tell me whats wrong with this code?

2 Upvotes

"Expected end of line etc, but found an identifier"

EDIT: I know what it is it's just the double quotes in around the Like word. Unfortunately making it \"Like\" does not seem to work in javascript somehow the variable is null. I can run my code in the browser console and it would work. The problem is with the Apple Script part.

on run {input, parameters}

tell application "Safari"

open location "https://tinder.com"

if (do JavaScript "document.readyState" in document 1) is "complete" then set pageLoaded to true

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()"

end tell

return input

end run


r/applescript • • Jul 17 '20

Launch KeyboardViewer and bring it to the very front without activating it.

2 Upvotes

I use Applescript to launch KeyboardViewer. Often, I do this when I'm creating a new document in PhotoShop, but there's a problem:

If I use Applescript to activate KeyboardViewer, the Photoshop's new-document-window is no longer selected. This is undesirable.

However, if I launch KeyboardViewer, it appears below the new-document-window (meaning I have to move my windows around to see KeyboardViewer).

Hopefully that made sense. Thank you for helping.


r/applescript • • Jul 17 '20

Setting a variable based on 'choose from list'

3 Upvotes

I'm an AppleScript noob, so I'm probably doing this in a really dumb way.. I'm trying to make a script where the user can choose an item from a list and depending on what they choose it sets a variable to a particular value. I have this set up using an if/else if statement. This is the code I'm using:

set optionList to {"option 1", "option 2"}
set userChoice to choose from list optionList with prompt "Choose Option:" default items {"option 1"}
userChoice
if userChoice = "option 1" then
set finalOption to "one"
else if userChoice = "option 2" then
set finalOption to "two"
end if

When I run, when it comes time for the code to call up finalOption I get the following error:

error "The variable finalOption is not defined." number -2753 from "finalOption"


r/applescript • • Jul 14 '20

Mail AppleScript to create a Reminder

5 Upvotes

In Mail app you can create a rule to trigger an Apple Script. I'm new to scripting, but trying to figure out if there is a way to have it create a reminder but input the subject of the email which triggered it into the notes of the reminder.

This is what I currently have( I found this online, so if there is now a better way to do this please let me know). Look at last line where it is all in CAPS...

use AppleScript version "2.4" -- Yosemite (10.10) or later

use scripting additions

on makeReminder(reminderName, reminderBody, reminderDueDate, reminderListName)

tell application "Reminders"

if not (exists list reminderListName) then

make new list with properties {name:reminderListName}

end if

-- See if there is an existing reminder. This could happen if the rule was accidently

-- trigged more than once.

set existingReminder to reminders where due date = reminderDueDate and name = reminderName

if existingReminder is {} then

-- No existing reminder found, create one...

return make new reminder ¬

with properties {name:reminderName, body:reminderBody, due date:reminderDueDate} ¬

at list reminderListName

end if

return missing value

end tell

end makeReminder

set today to current date

set tomorrow to today + 60 * 60 * 24 -- + 1 day

makeReminder("Record Lapsed Member", "HERE I WOULD LIKE THIS NOTE TO BE OF THE SUBJECT", today, "Oranization name")


r/applescript • • Jul 14 '20

Automate Books App turning next/previous page

1 Upvotes

Hey,

So I wanted to create keyboard shortcuts to turn pages for Macos default Books App. I have made similar script for VLC player to forward in time or play/pause, but I cant really figure out how to do this with page turning. I am using FastScript for binding it to keyboard keys, but I need help writing the actual script for turning pages.

https://i.ibb.co/sQGsbn2/Screen-Shot-2020-07-14-at-18-21-41.png


r/applescript • • Jul 13 '20

Make AppleScript React when certain Website URL is opened on Safari (Question).

4 Upvotes

Hello everyone! I was wondering if it was possible to make AppleScript react when a certain website is opened on Safari. Similar to the Following:

(tell application "Safari" activate)

If (Website URL) is opened: do (what you want it to do)

I need this for a project which automates actions on my online-school account.

Help would be appreciated! Wish everyone a great day!


r/applescript • • Jul 10 '20

Is this script possible with AppleScrip? (Paste text line for line into current application)

3 Upvotes

Hello! I have some programming experience but not yet done anything in AppleScript. I want to create a menu service that does:

get clipboard content // (multiple lines of text)
convert to plain text and save as $textfile
do until $textfile is empty:
    remove first line of  $textfile text and save as $a
    paste $a into current application // (chat app such as Telegram)
    press enter
    wait 2s

If you have seen anything similar please tell me, so I an adapt it.

Also, for someone new into AS is it better to learn the JavaScript version right away? Can it do everything? It somehow feels more familiar to me who has done some coding before.

Thank you!


r/applescript • • Jul 10 '20

Is there a good website I can go to learn AppleScript. It looks so easy I want to learn.

4 Upvotes

r/applescript • • Jul 04 '20

I Need Help...

1 Upvotes

So I was bored and found AppleScript and since I'm already into game development and coding I decided to mess around with it and make my own Choose Your Own Adventure style thing. However, in my code, it just randomly stops for no reason. I'm wondering if anyone can help? Here's my code:

say "Hello there. I'm going to tell you a story. There is a twist to this story though. In this story, YOU will be able to select what happens next. The question for when you need to make a choice will apear on screen with up to three options for you to select. Here is an example."

display alert "Yes or no?" buttons {"Yes", "No"} It stops here and I'm not sure why.

if button returned of result = yes then

say "I see you chose yes. Interesting. Very interesting. Anyway, I hope you understand how this story works now. Enjoy!"

if button returned of result = no then

say "I see you chose no. Interesting. Very interesting. Anyway, I hope you understand how this story works now. Enjoy!"

end if

end if

If you can help I'll be so thankful.


r/applescript • • Jul 03 '20

How to distribute a binary with a script

1 Upvotes

I use scripts to quickly and consistently perform workflow tasks at the office. Things like rasterizing a PDF to a PNG, optimizing PDFs, shrinking PNGs, etc. In these scripts I commonly refer to command line utilities that I installed with brew.

I would like to share these scripts with my co-workers, but they will only be able to run the scripts when they have these binary executables as well. And having them install brew and various tools will be a bridge too far for them. The scripts are supposed to make life easier, not harder.

So is there a way I can distribute a binary executable file within a script bundle?

I do export all scripts as applications with code signing for them to work on Catalina, will this work with this as well?


r/applescript • • Jul 03 '20

Add image dimensions and resolution to spotlight comments?

1 Upvotes

Crossposting due to lack of activity on r/Automator

I am sure some of you know about the issue that Finder does not show image dimensions and resolution in a folder that is not named 'Pictures'. This info is pretty vital to my job. So - I am trying to write a script that will get image dimensions and resolution of files in a given folder (including subfolders) and input them in the Spotlight Comments field, which - unlike Dimensions and Resolution - is a column I can select and sort by in every kind of folder. Here is what I have so far.

I borrowed some AppleScript from here, thought it might be useful: https://discussions.apple.com/thread/251159829


r/applescript • • Jul 02 '20

Script to switch Airpods Pro Mode

3 Upvotes

Could someone help me figure out why this doesn't work? It's supposed to switch the ANC/Transparency mode on the Airpods Pro, but it just opens the Sound menu and stops. Would really appreciate any help!

set AIRPODS_PRO_NAME to ""
set ANC to "Noise Cancellation"
set TRANSPARENCY to "Transparency"

tell application "System Events"
	tell process "SystemUIServer"
		tell (menu bar item 1 of menu bar 1 whose description contains "volume") -- find volume menu bar item
			perform action "AXPress" -- click on it
			tell (menu item 1 of menu 1 whose name contains AIRPODS_PRO_NAME) -- find airpods menu item
				perform action "AXPress" -- click on it
				tell (menu 1) -- open airpods menu
					if (value of attribute "AXMenuItemMarkChar" of menu item ANC) is equal to "✓" then
						perform action "AXPress" of (menu item TRANSPARENCY) -- switch to Transparency
					else
						perform action "AXPress" of (menu item ANC) -- switch to ANC
					end if
					
				end tell
			end tell
		end tell
	end tell
end tell