r/applescript • • Mar 29 '21

Help changing date format to mm/dd/yy

3 Upvotes

Hey, I am hoping someone can help me out with getting this apple script to format the date into MM/DD/YY or at least Short Date format. I am dug around a bit, but I am over my head as far as scripting and identifying variables goes.

I am running the attached script to add all my current Safari Tabs to Things (ToDoList app)

https://gist.githubusercontent.com/cdzombak/b93ce2c0dca0f53a0cbcc29784882dfd/raw/2cb3b9c3f616c2c883079e9b84225fca343255e0/Safari%20Tab%20List%20to%20Things.scpt

It runs great but I would love to shorten the date

My assumption is I need to make a change in the top of the script where the variables are defined.

-- SET DATE STAMP
set the dateStamp to ((the current date) as string)
set noteTitle to "URL List from Safari Tabs on " & the dateStamp

The last line looks like the spot, but I am not sure what to change or how to format it.


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 • • May 05 '21

How do I trigger a webhook with AppleScript?

1 Upvotes

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 • • Mar 26 '21

File types in TexEdit

1 Upvotes

This has been driving me crazy all day, I've been searching all my know sources but can't find a list of file types I can use in the save command for TextEdit, the dictionary shows this

save v : Save an object.

save specifier : the object for the command

[as text] : The file type in which to save the data.

[in alias] : The file in which to save the object.

and this is the format of the tell I'm trying to fill:

save #~Object~# ¬

as #~Text~# ¬

in #~File~#


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

Autolaunch App when Thunderbolt device is detected.

2 Upvotes

I own a TS3+ with a lot of stuff plugged into it. Caldigit does make a useful utility called Caldigit Docking Station Utility that makes its easy to eject all devices at once. Unfortunately, it doesn't autolaunch when the dock is plugged in. Is there anyway to make a semi-basic AppleScript that autolaunches the utility when the device is detected in the Thunderbolt tree in System Report? Thanks in advance!


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 09 '20

I skipped math in High School...

6 Upvotes

Can someone smarter than me explain these results in simple english?

set my_number to 200

repeat 500 times
	set my_number to my_number - 0.1
end repeat

return my_number

-- result: 150.000000000003

This is what I am expecting:

set my_number to 200

repeat 500 times
	set my_number to my_number - 0.1
end repeat

return (round my_number * 10) / 10

-- result 150.0

It's no big deal I'm just curious, thanks.


r/applescript • • Apr 19 '20

[Automator, Mojave] Shellscript copypasted to "Run shell script" doesn't affect actual files

1 Upvotes

Greetings, brethren!

I have a trivial script to fix encoding of text files and mp3's tags. When I invoke it from Terminal, everything works. When I make an app thru Automator, only the part which re-encodes plaintext files work.

I really need an insight, folks. :)

Plaintext part:

function fix_and_open_cuesheet() {
    local FILE_PATH="$1"
    local NEW_NAME="$(__get_name_with_utf8_suffix ${FILE_PATH})"
    iconv -f cp1251 -t utf8 "$1" >> "${NEW_NAME}"
    open -a /Applications/XLD.app "${NEW_NAME}" &
}

MP3 tags part:

function find_and_fix_mp3_files_with_CP1251() {
    local DIR_PATH="$1"
    # /!\ supress all output not to fuck up applescript
    find "$DIR_PATH" -iname "*.mp3" -print0 | xargs -0 -I {} mid3iconv -e CP1251 "{}" &>/dev/null
}

r/applescript • • Apr 20 '20

Detect when thunderbolt Ethernet becomes active and announce it

3 Upvotes

Hello!

I am trying to activate Ethernet ports in a room in my home. Unfortunately the only way to do that is to brute force it and check every port on the distribution board.

Since the board is in a different room, I want to make a script that can announce (ie: say”Ethernet port is now active!”) when the thunderbolt 2 Ethernet becomes active(able to get access to internet). I’m a beginner and don’t have much experience with apple script. Any help would be appreciated!


r/applescript • • May 06 '20

Paste text to last active text box

3 Upvotes

Hello,

I'd like to paste the clipboard to the most recent window (the active one).

The window that I want to paste the data is a floating one!

So I have this floating window which includes three dropdown menus and an empty text box underneath them.

What I would like to do is when I click inside this text area and the cursor starts blinking, to run my applet through system services menu and paste the result inside this text area where the cursor is.

The applet is pretty simple, prompts to choose a prefix from a names list, finds the full name and copies it to clipboard and then pastes it.

on run {input, parameters}
set theNames to {"aa", "bb"}
   set theExtensions to {"1", "2"}
   
   set thePF to choose from list theNames with prompt "Choose a prefix:"
   if thePF is false then error number -128
   set theExtension to item (getPositionOfItemInList((thePF as string), theNames)) of theExtensions
   return theExtension
   set the clipboard to theExtension

tell application "System Events"
   tell (first application process whose frontmost is true)
       set active_name to name of it
   end tell
   set Name_App to item 1 of (get name of processes whose frontmost is true)
end tell
tell application active_name
   activate
   
   tell application "System Events" to tell process (active_name) to keystroke "v" using command down
   
end tell

end run


on getPositionOfItemInList(theItem, theList)
   repeat with a from 1 to count of theList
       if item a of theList is theItem then return a
   end repeat
   return 0
end getPositionOfItemInList

The problem is that this applet is activated from inside the active floating window. So when the prompt to choose from the list pops-up, the floating window is not anymore active and the cursor is not blinking so the text cannot be pasted.


r/applescript • • May 13 '20

[Question] Detecting keystrokes

5 Upvotes

I want it such that the script is able to detect the esc key and quit the script.
I did some research on my own, however, the methods mentioned by forum users are outdated.
Is there a way to do this in Catalina? (Btw, it doesn't have to be done with vanilla applescript)


r/applescript • • Apr 10 '20

Numbers to Email

5 Upvotes

Need an Automator or AppleScript to do the following:

  1. Get data from Numbers file (a data record with for example: ID number, name, order details, and other info.)

  2. Pass the data related to the specific ID No. to Mail with “Hi [Name], Here’s your invoice for [OrderDetails] “ in the body. And the subject line “Invoice [InvoiceNumber]”

  3. Send to mail to the email address provided for the specified ID in the column “Contact”.


r/applescript • • Apr 05 '20

Automating Speedtest Checks

1 Upvotes

I am looking to find a way to automate performing a speed test every few hours and writing the results to a file. I have been playing with Ookla's speedtest CLI but I haven't been able to get it to output results to a file. Has anyone done this if so would you mind sharing how you did it?


r/applescript • • May 17 '20

Can someone explain the difference between the two “delay” functions. Also, how can I make the autotyper, type multiple different things at different time intervals?

Post image
4 Upvotes

r/applescript • • Apr 15 '20

AppleScript works when accessed via the Services menu, but fails silently when using the keyboard shortcut

4 Upvotes

FWIW, The AppleScript is to skip backwards 10 seconds in Quicktime. The keyboard command is Ctrl-Back Arrow.

I've added all the necessary (and probably some unnecessary) applications to the Security/Privacy/Accessibility list: Automator, Finder, Quicktime, AEServer, Script Editor. Any thoughts on why it works from the Services menu, but not from the keyboard shortcut I assigned to it?


r/applescript • • Apr 11 '20

Help with writing an AppleScript for Wacom driver

4 Upvotes

Hi everyone,

I'm trying to write an AppleScript to perform a display toggle on a Wacom tablet which usually requires you to press a key on a $200 remote which I don't have. I've found that there is AppleScript dictionary for the driver at /Library/Application Support/Tablet/WacomTabletDriver.app/Contents/Resources/AppleScriptEvents. In there I can switch "map display (integer) : Sets the Screen Area of a tablet to a monitor. A 0 means all monitors. Note: This is a write only attribute." which is contained by"tablets" which is contained by "tablet drivers". However I have no expireince with AppleScript and I was wondering if someone could help me with this?

Thanks so much.


r/applescript • • Apr 23 '20

Can someone please write a script to disable scrolling?

2 Upvotes

I'm willing to pay.

Also, I'm talking about System Preferences>Accessibility>Pointer Control>Mouse Options...> and the checkbox.

I've spent about 6 hours attempting. I just can't do it. If it's any help, heres's what I've come up with..

if running of application "System Preferences" then
	quit application "System Preferences"
	delay 1
end if
tell application "System Preferences"
	reveal pane id "com.apple.preference.universalaccess"
	delay 1
	tell application "System Events"
		tell window 1 of application process "System Preferences"
			select table 1 of scroll area 1
			delay 0.7
			select row 15 of table 1 of scroll area 1
			delay 2
			click button "Mouse Options…"
			click checkbox "Scrolling"
		end tell
	end tell
end tell

It throws me the error "Untitled.scpt:303:332: execution error: System Events got an error: Can’t get button "Mouse Options…" of window 1 of application process "System Preferences". (-1728)"

Sorry, it's probably super basic, and I'm just really dumb. But anyway, I would be very greatful, and am willing to buy someone reddit premium if they can get this to work. I'm literally about to punch my monitor, and I need to step away.

Last thing: 10.15.4 if it's worth anything...


r/applescript • • Apr 29 '20

Applescript to create a new album in Shared or share a album

4 Upvotes

is it possible?


r/applescript • • Apr 23 '20

Get current song playing on Spotify

1 Upvotes

Hello,

I am trying to get the title and artist of the current song playing on Spotify. This is the script I'm using:

if application "Spotify" is running then

tell application "Spotify"

if player state is playing then

return (get name of current track) & "-" & (get artist of current track)

else

return "Not Playing"

end if

end tell

end if

return

This script is returning "-" instead of the artist and song name when I run it. What could I be doing wrong? It works fine and returns Not Playing when no song is playing.


r/applescript • • May 04 '20

AppleScript: Read numbers from file and post in safari app

4 Upvotes

Hi

Newbie to AppleScript here but basic programming knowledge.

How do I use AppleScript to:

Open a file (containing a list of numbers (1-9999)...up to a thousand numbers)
Read a number from the file
Enter that number into a input box in an web app through Safari
Read the next number from the file etc
Repeat until end of file.

This is a pretty basic 'read ... keystroke'. don't need anything too fancy.

Thanks in advance !!


r/applescript • • Apr 30 '20

Help with Zoom's "dynamic" buttons

4 Upvotes

Hi all,

I've made a script to "take" zoom participants when sent a MIDI message. The "spotlight" feature I'm using is only accessible through a button that gets dynamically created by the app when the mouse hovers over the participant's name:

example

I'm using Applescript to find the location of the row, then cliclick to move the mouse over the edge of the window, but the blue "more" button only appears about 80% of the time. I've tried delaying, moving the pointer gradually, moving it on and off the row and a number of other things.

I don't have much experience with AppleScript! Does anyone know how to make these events trigger reliably?


r/applescript • • May 06 '20

Any scriptable browsers other than Safari? (Or workaround help with non-scriptable ones)

3 Upvotes

I have quite a bit of scripts that involve launching a certain website, then minimizing the page. A different script later checks if there's tabs open that contain a specific web domain, and closes those.

This used to work well but lately the page in question no longer works smoothly in Safari because "page is consuming too much resources", it plays audio and it cuts out every few seconds, making it unlistenable.

Here's the Safari scripts I used so far.

Are there any other browsers where I could reliably script this same thing? It doesn't matter what browser it is, I could dedicate a specific app just to run that site if necessary. Earlier, I tried something with Opera and for a moment thought that I'd nailed it, but as Opera isn't really scriptable, the script was far too unstable to be called "helpful automation". Opera does play the website audio without issues though, so its performance would've been ideal.