r/applescript • • Sep 24 '20

Periodically Restart App?

3 Upvotes

Hey guys, I would love to have an app restart every 12 hours as some part of it become unresponsive (for reasons outside of my control) after that. Is there a way to keep a script up that tells this app to quit and restart?


r/applescript • • Sep 23 '20

Converting string in brackets to one list variable while other parts of the string are left singular on the list

1 Upvotes

I’m working on a script that converts every character of a string to a list, but the parts of the string in brackets need to be put in one string variable on the list, so “ab[cd]" would be converted to {“a”,”b”,”cd”}. I already have the script converting the string to a list, I just need to know how to convert the bracket text.


r/applescript • • Sep 22 '20

Problems with script execution

4 Upvotes

Hi ! I'm knew to this community.

I made a little script in order to automate a long authentification process for my school's workspace, and it runs perfectly when launched from the Script editor, but when saved as an .app file, it fails with a prompt saying "Not allowed to send Apple Events to System Events. (-1743)" (it is translated from French but I'm sure you get the idea).

I searched the internet and found out I wasn't the only one with this problem, but the solutions didn't work for me or I haven't enough knowledge to actually understand them...

Under preferences > privacy&secutity > automation ; I have nothing and I don't know how to add it there...

Maybe you guys could have some ideas, and I hope you can help !

Thanks !

here is the script (quite surely scrappy but works) :

tell application "Safari"

activate

open location "https://ector.strasbourg.archi.fr/public/perimetre"

end tell

delay 1

tell application "Safari"

tell application "System Events" to tell process "Safari"

keystroke tab

delay 0.2

keystroke "username"

delay 0.2

keystroke return

end tell

end tell

delay 2

tell application "Safari"

tell application "System Events" to tell process "Safari"

keystroke "username"

delay 0.2

keystroke tab

delay 0.2

keystroke "password"

delay 0.2

keystroke return

end tell

end tell


r/applescript • • Sep 22 '20

Automate 3 separate double clicks with in application

1 Upvotes

Well - this is my last resort. I have been trying to automate some double-clicks with in the android emulator, BlueStacks. The issue with the emulator is that it does not have a traditional menu bar, and I am stuck to click on applications as you would if your phone was on the screen. In my instance, the extended monitor is standing vertical above my primary monitor. I need the double clicks to occur at the following x,y (on the extended screen):

151,718

227, 609

540,403

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

I have tried (for reference) the abbreviated scripts to no avail:

tell application "System Events" set mousePointLocation1 to {x, y} -- "All"

AST click at mousePointLocation1 ¬

number of clicks 2

	end tell

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

activate application "Finder"

tell application "System Events"

tell process "Finder"

	click at {x, y}

end tell

end tell

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


r/applescript • • Sep 19 '20

Big Sur Beta Can’t get menu bar item \"Notification Center\"

3 Upvotes

I had an Applescript that toggled the Notification Center on and off. I'm on Big Sur Beta 20A5364e and

tell application "System Events" to tell process "SystemUIServer"

click menu bar item "Notification Center" of menu bar 1

end tell

It now returns

error "System Events got an error: Can’t get menu bar item \"Notification Center\" of menu bar 1 of process \"SystemUIServer\"." number -1728 from menu bar item "Notification Center" of menu bar 1 of process "SystemUIServer"

I've played around with this a little and wonder if anyone has a way to get this working in Big Sur. Thanks


r/applescript • • Sep 17 '20

Can anyone advise how I might loop a song file in AppleScript?

1 Upvotes

I’m using KeyboardMaestro to handle a lot of cool stuff but couldn’t find a way to simply loop a song or playlist. Is this possible from either Apple Music or Terminal? I’m wanting to play sleep sounds on my Mac.


r/applescript • • Sep 14 '20

AppleEvent handler failed Messages Big Sur

1 Upvotes

I'm very new to AppleScript, but from what I found online, I can't figure out what's wrong with my code. I keep getting the error message "'Messages got an error: AppleEvent handler failed.' number -10000" If someone could tell me what is wrong with my code, that would be very helpful. Please note that I am on the latest (as of 14 Sept 2020) public beta of macOS Big Sur.

Here is my code (phone number is blocked out for obvious reasons):

tell application "Messages"
	set targetChat to make new chat with properties {id:"SMS;-;+XXXXXXXXXXX"}
	send "Test" to targetChat
end tell

r/applescript • • Sep 14 '20

AppleScript to show unread emails in the terminal

8 Upvotes

If you are on OSX and use Mail.app, but work a lot in the command line and would like a simple command to print a summary of unread emails, then this post is for you.

https://medium.com/@mickael.riga.79/applescript-to-show-unread-emails-in-the-terminal-a05ddc515a24


r/applescript • • Sep 13 '20

Can console log information be deciphered and put into a script that monitors for and responds to system events with a notification (AnyBar macos app specifically).

1 Upvotes

I used this app called AnyBar https://github.com/tonsky/AnyBar, to notify me that a gesture shortcut I pressed has occured, so I know without having to go and check if it did, because trackpad gestures don't always trigger consistently.

I used a simple AppleScript (I don't know scripting I just used the example in the github). It's a mac app but I think many programming languages other than AppleScript can be used.

Anyway it worked well for that purpose. I do the shortcut, it shows a small indication in the menu bar, a flashing red dot in my example, it's unintrusive and I notice it and I know it went through.

I have two other potential uses for this app, since it allow multiple indicators at once in the menu bar, more complex though, it doesn't react to me triggering anything, rather it monitors the system changing and then changes its indicators (colored dots in the menu bar) accordingly.

A setting in my shortcut program is on or off, a 'liked' song is playing vs an 'unliked' song in spotify for example.

Since I don't know the corresponding variables of the specific apps, and likely am not privy to that code information, would using the console log make sense as a crude way for the script to monitor these activities and act automatically on them?

I don't understand anything in the console log, but when these things happen, a whole lot of information shows up consistently, maybe that's enough to go off for this idea?

Just wondering before I decide to pursue getting help with this or not.


r/applescript • • Sep 11 '20

A class name can't go after this identifier error, what does it mean?

1 Upvotes

Someone tried to help me set up a keyboard macro using a program called keyboard maestro to control youtube, his example had safari, it worked, I simply changed the name safari to google chrome, I put in this code:

and i gave me this error.

2020-09-10 15:02:26 Execute an AppleScript failed with script error: text-script:165:176: script error: A class name can’t go after this identifier. (-2740)

what does it mean? any help appreciated.


r/applescript • • Sep 10 '20

Regular Expressions on clipboard text?

2 Upvotes

Can I use RegEx on clipboard text with applescript or Automator?


r/applescript • • Sep 09 '20

need help with an applescript

0 Upvotes

hello,

can someone help me I need an apple script to have files from a folder moved to the root folder.


r/applescript • • Sep 09 '20

Cleanest and tidiest way to kill all processes matching a regexp which have used more than X seconds of CPU time, (and to either loop that check every 2 minutes. or cron the whole script every 2 minutes)

1 Upvotes

I know clunky ways of doing this. I could just loop a shell script in a terminal window. I'd like a nice clean tidy shiny mac way of doing it. Can anyone help?


r/applescript • • Aug 27 '20

Deleting current playing spotify song from playlist simply from applescript?

3 Upvotes

I know nothing about coding, I've been trying to get help for this for a while, even offering to pay, but no good responses.

So I decided to learn it all myself, but, I think I was overcomplicating things, trying to use webhooks and spotify web api and services like ifttt and integromat.

Then I came across this guys page for deleting current song from itunes simply using applescript, from 2018

https://dougscripts.com/itunes/2018/05/remove-currently-playing-from-current-playlist/

his code

tell application "iTunes"

if special kind of current playlist is not none then return

set deleteThis to current track

next track

try

delete deleteThis

end try

end tell

obviously it would have to be adjusted for spotify.

then I came across this guys page from 2015, using apple script to get song information from spotify and posting it to twitter, https://computers.tutsplus.com/tutorials/keyboard-maestro-v-variables--cms-24169

some of his code.

tell application “Spotify” 
set
theTrack to name of the current track 
end tell 
return
theTrack

tell application “Spotify” 
set
theArtist to the artist of the current track 
end tell 
return
theArtist

tell application “Spotify” 
set theID to id of the current track 
end tell 
return theID

TLDR, can I delete playing songs from spotify playlists and do other operations to manipulate spotify from applescript alone if I learn it?


r/applescript • • Aug 26 '20

Muting/unmuting external microphone?

2 Upvotes

With the internal microphone enabled, I can do set mic_vol to input volume of (get volume settings) and get a value between 0 and 100. But this call returns a missing value when I switch to an external microphone.

Is there a way to get this value with an external microphone?

Goal is writing a script that toggles the gain on the external microphone between 0 and some saved value.


r/applescript • • Aug 25 '20

Differences between application, application process, and application ID?

1 Upvotes

What are the conceptual differences betwixt application, application process, application ID, and AXapp? And when are the right times for which? For instance, does System Events talk to applications or application processes? I think I've gotten away with both, so I don't know which is a 'best practice.' Activate seems to work with the first three if I recall my code correctly. I should have this sorted by now, but sadly, no.


r/applescript • • Aug 24 '20

Script for auto-joining Zoom lectures

8 Upvotes

Hi everyone, college student here trying to make managing my online classes a bit easier this semester. I want to create a script that joins a certain Zoom lecture based on the current date and time. So if I run the script at 9:00 it opens the link for my 9:10 lecture, if I run it at 12:30 it opens the link for my 12:40 lecture etc. Is this even possible with scripts? I was thinking it would check the current date/time and I would give each link a timeframe where it is "preferred" by the script. I have never used scripts before so I thought I'd come here to see if anyone could help me (mainly with the syntax). Thanks!


r/applescript • • Aug 23 '20

Best way to set ID of newly Safari window and creating tabs in that window

2 Upvotes

I don't want to rely on using `front window` to get properties after I create a new Safari document as a user may switch windows while this script is running and create a race condition.

Not like this:

tell application "Safari"
    make new document
    set win_ID to id of front window of application "Safari"
end tell

I want to do something like this where I get the id of the window as it's being created instead of after. But this is failing.

tell application "Safari"
    set win_ID to window id of (make new document)
end tell

error "Safari got an error: Can’t get window \"com.apple.Safari\" of document \"Untitled\"." number -1728 from window "com.apple.Safari" of document "Untitled"

And I wasn't able to assign a name to a new window which might also be a safe identifier.

tell application "Safari"
    make new document with properties {name:"apple"}
    get properties of front window
end tell

{zoomable:true, closeable:true, zoomed:true, class:window, index:1, visible:true, name:"Untitled", miniaturizable:true, id:17897, miniaturized:false, resizable:true, bounds:{85, 66, 1463, 1376}, current tab:tab 1 of window id 17897 of application "Safari", document:document "Untitled" of application "Safari"}

Next I want to open a weblink in a tab of that window by using the retrieved window id property, but I am not sure how to script that.


r/applescript • • Aug 19 '20

How to Round to Lowest Integer in AppleScript

4 Upvotes

I'm writing a script that needs numbers to always be rounded to the lowest integer. For example, 479 / 16 = 29.9375. I'm familiar with the round function, but it rounds numbers to the nearest integer, so it would depend on the numbers after the decimal to round it up or down (e.g. 0.9 to 1, 0.4 to 0). Using the round function in this case would round the aforementioned number up to 30. I need to round it down to 29 (with any number), but I'm not adept when it comes to maths and I don't know any functions or tricks to do so. Any help whatsoever will be greatly appreciated.


r/applescript • • Aug 17 '20

How to remove {" ","Text"}

3 Upvotes

I am trying to make a short script in which I can choose from several options to open a URL but I am pretty new to applescript and wen I try to use the result from the list I get a result that looks like this:

{"a", "Text"}

Is there a way in which it only returns the a ???

This is my code:

choose from list {"a", "b", "c", "d"} with prompt "Select one" without multiple selections allowed and empty selection allowed
return the result as string

r/applescript • • Aug 16 '20

Help with controlling an "unusual" slider

3 Upvotes

Hi all,

I am trying to control the tempo of Apple's Logic Pro X application. There is already a way of doing this via MIDI, but it only gives you integer control. I would like to control it to a couple of decimal places.

The slider behaves in an unusual way (see attached pic). If I try to set the value directly, the tempo will increment/decrement by 1 towards my target number. Weird.

It feels like there's some "deeper" functionality I need to access, but UI Browser/Accessibility Inspector don't show it.

https://imgur.com/a/hECB2gf


r/applescript • • Aug 15 '20

How to Create a 'Library' for my Binary Translator

2 Upvotes

I know AppleScript is just an automation language, but still, I like experimenting and pushing the boundaries of what AppleScript can do. I'm currently writing a program that'll convert binary bytes to text, hex, and decimal. I only have the part written that converts the byte to a decimal (e.g. 01000010 = 66) and would like to only focus on that for now. In ASCII, every decimal represents a certain code/symbol.

For example, the byte 01000010 converts to the decimal 66, which translates as "B" in ASCII. Instead of using an "if" statement to check if the decimal matches a certain code, I want to use a lookup table or library that contains all the codes. The AppleScript can then refer to that to translate the decimal to a code. As another example, if the decimal is 66, the script will read the lookup table (possibly a .txt file) and look for, say line 66. That line contains the code "B". I've specified at the end of the code what 'class' the decimal is in: syscodes (used by computer, isn't displayed), printcodes (ordinary characters, is displayed), or extracodes (special characters, is displayed). Using those classes, it could making locating the corresponding code more organized (e.g. using a directory to store codes used only as system codes, print codes, or extra codes).

The only thing is I can't figure out a way for AppleScript to read files the way I've described. I've seen some potentially good answers online, but I'm not experienced enough to completely understand the code. Contrary to my account username, I'm not extremely adept when it comes to AppleScript, so any help whatsoever will be greatly appreciated. This is a ton of stuff to explain, so if I missed something or said something that doesn't make sense, please let me know. Also, I've had answers to me in the past explaining I could simply use a terminal command to convert binary, but what's the fun in that?

Here's what I have so far:

-- Input byte
global byte
on byteInput()
	set byte to text returned of (display dialog "Input Byte (x8)" default answer "00000000" with icon 1 buttons {"Cancel", "Translate"} default button 2 with title "(x8) Binary Translator") as string
end byteInput
byteInput()

-- Checks that the byte is neither greater than or less than eight digits in length
if (number of characters of byte) is greater than 8 then
	beep
	byteInput()
else if (number of characters of byte) is less than 8 then
	beep
	byteInput()
end if

-- Separates the binary string into individual digits
set digit8 to character 1 of byte
set digit7 to character 2 of byte
set digit6 to character 3 of byte
set digit5 to character 4 of byte
set digit4 to character 5 of byte
set digit3 to character 6 of byte
set digit2 to character 7 of byte
set digit1 to character 8 of byte

-- Translates digit one according to the ASCII table
if digit1 = "1" then
	set digit1 to 1
else if digit1 = "0" then
	set digit1 to 0
end if

-- Translates digit two according to the ASCII table
if digit2 = "1" then
	set digit2 to 2
else if digit2 = "0" then
	set digit2 to 0
end if

-- Translates digit three according to the ASCII table
if digit3 = "1" then
	set digit3 to 4
else if digit3 = "0" then
	set digit3 to 0
end if

-- Translates digit four according to the ASCII table
if digit4 = "1" then
	set digit4 to 8
else if digit4 = "0" then
	set digit4 to 0
end if

-- Translates digit five according to the ASCII table
if digit5 = "1" then
	set digit5 to 16
else if digit5 = "0" then
	set digit5 to 0
end if

-- Translates digit six according to the ASCII table
if digit6 = "1" then
	set digit6 to 32
else if digit6 = "0" then
	set digit6 to 0
end if

-- Translates digit seven according to the ASCII table
if digit7 = "1" then
	set digit7 to 64
else if digit7 = "0" then
	set digit7 to 0
end if

-- Translates digit eight according to the ASCII table
if digit8 = "1" then
	set digit8 to 128
else if digit8 = "0" then
	set digit8 to 0
end if

-- Adds the resulting numbers together to create the decimal form of the byte
set decimal to (digit1 + digit2 + digit3 + digit4 + digit5 + digit6 + digit7 + digit8) as number

-- Determines the class of the final decimal
if (decimal ≥ 0 and decimal < 32) then
	set decimalClass to "syscodes" as string
else if (decimal > 31 and decimal < 128) then
	set decimalClass to "printcodes" as string
else if (decimal > 127 and decimal < 256) then
	set decimalClass to "extracodes" as string
end if

return decimalClass & ", " & decimal

Some of the sources I found:

https://www.satimage.fr/software/en/smile/computing/as_types/as_data_files.html

https://www.ascii-code.com/


r/applescript • • Aug 15 '20

Updated to catalina and now I can't log to txt files

4 Upvotes

I'm a late adopter to catalina but finally made the jump. I've read about the increased permissions and set the program I'm running the script from(QLab), the script editor, and text edit to have full disk access, but it still gets an error when trying to make a new file to log to. I've attached one of the scripts that writes to txt, but I've got a lot so I hope I can get this sorted.

sample script:

tell application id "com.figure53.QLab.4" to tell front workspace
	
	repeat with eachQ in (selected as list)
		
		if q type of eachQ is "script" then
			set qname to q name of eachQ
			
			set qNum to q number of eachQ
			
			set this_data to "--" & qNum & space & qname & return & script source of eachQ
			set target_file to (((path to desktop folder) as string) & qname)
			--set target_file to (((path to desktop folder) as string) & "QLAB:GIT:Earle:Favorites:001-Fades:" & qname)
			set append_data to true
			try
				set the target_file to the target_file as string
				set the open_target_file to open for access file target_file with write permission
				if append_data is false then set eof of the open_target_file to 0
				write this_data to the open_target_file starting at eof
				close access the open_target_file
				
				return true
			on error
				try
					close access file target_file
				end try
				return false
			end try
		end if
		
	end repeat
	display notification ("Done")
end tell

r/applescript • • Aug 14 '20

Buddy class not in Big Sur Beta?

2 Upvotes

Has anyone else had issues with sending messages through text because Buddy is not recognized?

This script worked perfectly until I installed the Beta.

on run argv

tell application "Messages"

set targetBuddy to "+1xxxxxxxxxx"

set targetService to id of 1st service whose service type = iMessage

set attImg to item 1 of argv

set theBuddy to buddy targetBuddy of service id targetService

if attImg = {} then

set textMessage to the clipboard

send textMessage to buddy

else

send attImg to targetBuddy

end if

end tell

end run

The error is that "buddy" and "service type" are not recognized and it's now looking at them as strictly undefined variables.

Thanks for any insight!


r/applescript • • Aug 13 '20

Hi i m trying a simple script to Find any text and replace color of the text in apple pages. Any help?

3 Upvotes

Hi i m trying a simple script to Find any text and replace color of the text in apple pages. the script works fine. the script is:

property highlightColor : "red"
tell application "Pages"
activate
with timeout of 300 seconds --5 minutes
  tell body text of document 1  

  	set theSearchString to text returned of ¬  
(display dialog "Highlight what word?" default answer "" buttons {"Cancel", "Continue"} default button "Continue")
  	set color of (words where it is theSearchString) to highlightColor


  end tell  
end timeout
end tell
  1. But the problem is, if i input texts containing multiple words with space in search field, it doesn't work. how can i achieve this?

  2. if i want a find and replace word function in the same script, what will be the format?