Hi folks,
I've got some music that I want playing on iTunes all the time on an older system, but it'll sometimes stop. I tried making a Applescript to check and play the music/playlist again if it stops, but I keep getting a timeout error.
This is the AppleScript:
repeat
tell application "iTunes"
if player state is paused then
tell application "iTunes" to play
end if
delay 30
end tell
end repeat
I get this error:
AppleEvent timed out.
iTunes got an error: AppleEvent timed out. (-1712)
I can't figure out why I'm getting a timeout error... anyone have any ideas?
AppleScript
RSS for tagAppleScript allows users to directly control scriptable Macintosh applications as well as parts of macOS itself.
Posts under AppleScript tag
39 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Hello everyone,
I would like to use AppleScript to transform a .csv file.
To make things easier to understand, I'm attaching two files:
1- The original file in csv format
2- The file as I'd like it to look after I've run it through the script.
Here are the steps involved
1-Open the file in numbers (Note: the file is located in the download folder).
2-Delete the first 6 lines
3-Delete all font styles and cell colors
4-Combine all cells in the nature of operation column of the same operation belonging to the same date in the first cell of the operation, deleting all spaces in the text is not necessary for each operation.
5- Delete all empty lines.
I hope I've made my request clear.
If any of you have the knowledge to do this, if it can be done at all, I'd be very grateful for their help in writing the script.
Thank you in advance.
1.csv
2.csv
I'm trying to use Image Events instead of Photoshop to manipulate a bunch of images.
I need to extend the canvas and have the padding be white. I've tried
pad theImage to dimensions {545, 545} with pad color {65535, 65535, 65535}
But that does nothing. If I remove the 'with pad colour...' part, it works but the pad defaults to black. I've looked everywhere, but there doesn't seem to be a solution.
Is there one?
I have a bunch of images sized 540px on the long side (some portrait, some landscape). The other side could be any size, but will be less than 540. There are no square images.
I want to be able to choose a folder containing the images, and want the script to do the following for each image:
Place it at the center of the current page of the active indesign document. Scrape the filename from the image (without the extension), apply the pre-existing Paragraph Style 'Caption' to the text, and center the text 36 points (not pixels) below the image.
Group the image and the text.
Then create a frame with white fill, 540x600 pixels in size, send it to back, center it with the group created above, and group them.
I've been pulling my hair out. Just can't get it to work.
We created a script .scpt that is run before an operation. the script use a login via Safari. almost always it works but sometimes not. if we log on the machine the script will work. do you have idea of the problems? Thanks
I have:
an Automator workflow saved as an application "workflow.app"
an Apple Script saved as an application "script.app"
a PDF file residing on Desktop "test.pdf"
How do I launch workflow.app and pass test.pdf as the input for workflow from inside script.app?
I am unable to get a result from a simple AppleScript calculator set of commands.
The calculator shows the right result, but I cannot capture the result to place in the clipboard and read it.
I also ran this in the script editor.
Python File
Hello.
tell application "Microsoft Excel"
Where can I find complete help for all Excel commands?
I am trying to export my AppleScript as an application and have enabled my developer ID to sign it. I, however, get an error the following error:
Any ideas?
Thank you and best regards,
pd
NOTE: macOS Sonoma 14.7.
I have a VBScript routine to print envelopes by automating Word. This works just fine.
Now I'm trying to do the same thing with AppleScript, also using the Word application. Here is what I have so far:
set recipientAddress to text returned of (display dialog "Enter the recipient's address:" default answer "")
-- Prompt for recipient city, state, and zip
set recipientCityStateZip to text returned of (display dialog "Enter the recipient's city, state, and zip:" default answer "")
-- Combine all address parts into a full address
set fullAddress to recipientName & return & recipientAddress & return & recipientCityStateZip
-- Create a new Word document and print the envelope
set dialogResult to display dialog "To print envelope for:" & return & return & recipientName & return & recipientAddress & return & recipientCityStateZip & return & return & "Center envelope upside-down in printer with flap on left" & return & return & "Continue?" buttons {"Yes", "No"} default button 2 with icon caution
if button returned of dialogResult is "Yes" then
tell application "Microsoft Word"
set wdDoc to make new document
-- Print the envelope with the collected recipient address and hard-coded return address
-- wdDoc's print out envelope(address:fullAddress, returnAddress:returnAddress)
-- Close the document without saving
close wdDoc saving no
end tell
end if
What does NOT work is the commented line near the end of the script which starts with -- wdDoc's print out envelope...
Either I am doing it wrong, or Word for Mac can't be automated that way. Can anyone help with this script, or at least suggest a different method to print an envelope on demand?
Thanks...
Context
I'm working on a Mail.app plugin. I would like to disseminate plugin via AppStore.
I'm interested in exposing a functionality to user enabling user to choose if plugin should apply to all or selected email account.
My intention is to use AppleScript to get a list of available email accounts and expose the list to the end-user via SwiftUI
Sourcing account information
Apple Script
I'm using the following AppleScript
tell application "Mail"
set accountDict to {}
repeat with acc in accounts
set accName to name of acc
set accEmails to email addresses of acc
set accountDict's end to {accName:accEmails}
end repeat
return accountDict
end tell
The above generates expected results when executed using Script Editor.
Swift Implementation
This is still incomplete but shows the overall plan.
//
// EmailAccounts.swift
import Foundation
enum EmailScriptError: Error {
case scriptExecutionError(String)
}
struct EmailAccounts {
func getAccountNames() -> [String]? {
let appleScriptSource = """
tell application "Mail"
set accountDict to {}
repeat with acc in accounts
set accName to name of acc
set accEmails to email addresses of acc
set accountDict's end to {accName:accEmails}
end repeat
return accountDict
end tell
"""
var error: NSDictionary?
var accountNames: [String] = []
// Create script object, exit if fails
guard let scriptObject = NSAppleScript(source: appleScriptSource) else {
return nil
}
// Execute script and store results, nil on error
let scriptResult = scriptObject.executeAndReturnError(&error)
if error != nil { return nil }
// Iterate over results
for index in 0...scriptResult.numberOfItems {
if let resultEntry = scriptResult.atIndex(index) {
if let resultString = resultEntry.stringValue {
// Process result handling
// accountNames.append(resultString)
}
}
}
return accountNames
}
}
Questions
Most important one, can I deploy the App on the App Store and use NSAppleScript as shown above?
If yes can I use the script in the manner shown above or will I need to store the script in User > Library > Application Scripts location and source it from there. This is outlined in the Scripting from a Sandbox article by Craig Hockenberry, which I cannot link due to being hosted within a not-permitted domain.
If yes what entitlements I need to give to the target.
I understand that I wouldn't be able to use ScriptingBridge, which feels more robust but wouldn't permit me to deploy the app on the AppStore.
My key objective is to programatically identify mail accounts available to Mail.app, if there is a wiser / easier way of doing that I would be more than receptive.
Topic:
App & System Services
SubTopic:
Automation & Scripting
Tags:
Entitlements
AppleScript
Mail Extensions
App Sandbox
I have a string of the form “Mon 22nd April”. I’m trying to extract the day (i.e. Mon), the date (i.e. 22nd) and the month (i.e. April) using this Applescript:
set originalDateString to “Mon 22nd April”
-- Extract the components by splitting the string
set AppleScript's text item delimiters to " "
set dayOfWeekAbbrev to text item 1 of originalDateString
set dayOfMonth to text item 2 of originalDateString
set monthName to text item 3 of originalDateString
When I run this on its own it works as expected:
dayOfWeekAbbrev is set to “Mon”
dayOfMonth is set to “22nd”
monthName is set to “April”
When I run this inside a bigger script involving Numbers, the text item delimiters fails to work, no compile or run time errors occur and I end up with:
dayOfWeekAbbrev is set to “M”
dayOfMonth is set to “o”
monthName is set to “n”
I.e the first three characters of the string.
If I replace originalDateString with the literal string “Mon 22nd April” I get the same result. In other words, text items and being recognized as individual characters, no delimiter (or delimiter is null). Totally confused.
I have tried to manually install binaries using Finder by clicking and dragging from the Desktop into "/usr/local/bin/". The binaries come with a collection of frameworks etc. All the binaries are adhoc signed. macOS asks for Admin credentials which is fine. But then, when I execute the binaries in Terminal, Gatekeeper shows the now expected "'[binary"] Not Opened Apple could not verify ........" etc. It shows that dialog for every component and requires user input 2-3 times to allow each component of which there are perhaps dozens.
BUT, none of that happens if I install those binaries using AppleScript. So, it might have a call like this:
do shell script "curl -L " & download_URL & " -o " & download_binary_zip with administrator privileges
do shell script "unzip -o " & download_binary_zip & " -d " & usr_bin_folder with administrator privileges
The resulting installs work perfectly.
Is this intended ? Using both install methods requires Admin credentials. Why does using a script work but using Finder does not ?
Hi Team,
In previous macOS version, We were using this link to open system extension permission page programmatically for our swift app. x-apple.systempreferences:com.apple.preference.security?General
In macos 15 (Sequoia), this pane is moved to system settings-> general->login Items and extensions->end point security extensions which is a modal/popup.
Can you please share what should be link to open exact this popup for asking permissions.It appears when you click on i button against end point security extensions
Based on apple script I could find following link but it opens login item & extensions pane, I want the next popup as above screenshot.
"x-apple.systempreferences:com.apple.LoginItems-Settings.extension?extensionItems™
Topic:
Privacy & Security
SubTopic:
General
Tags:
Preference Panes
AppleScript
Core Services
Endpoint Security
Hello all, I need some guidance please. Since recent security changes at Microsoft. AppleMail and Outlook on my very old MacBook (El Capitan) can no longer send/recieve emails as authorisation cannot bind. Before I could automate email (hotmail account) sending with AppleScript. I now use a web mail page for Outlook via Chrome but having to send manually. Can I get some advice on how to control, with AppleScript, the attached webpage to:
open a new email
add recipient in the To field
add a subject
attach a file
send email.
Or is there another solution (apart from buying a newer Mac!). Thank you
Hello, I don't know much about AppleScript, but I found this script on a Raycast site that dismisses Notification Center notifications. It worked great on Sonoma but has stopped working in Sequoia. Here is the code:
tell application "System Events"
tell process "NotificationCenter"
if not (window "Notification Center" exists) then return
set alertGroups to groups of first UI element of first scroll area of first group of window "Notification Center"
repeat with aGroup in alertGroups
try
perform (first action of aGroup whose name contains "Close" or name contains "Clear")
on error errMsg
log errMsg
end try
end repeat
-- Show no message on success
return ""
end tell
end tell
When using this to attempt to dismiss notifications, it returns the following error:
Can’t get scroll area 1 of group 1 of window "Notification Center" of process "NotificationCenter". Invalid index. (-1719)
Please help me fix it so it will run in Sequoia! This script was super useful.
When calling a perl script from an apple script (by dropping a file on it), I get the error:
Can't load '/Library/Perl/5.34/darwin-thread-multi-2level/auto/Encode/Encode.bundle' for module Encode: dlopen(/Library/Perl/5.34/darwin-thread-multi-2level/auto/Encode/Encode.bundle, 0x0001): tried: '/Library/Perl/5.34/darwin-thread-multi-2level/auto/Encode/Encode.bundle' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Perl/5.34/darwin-thread-multi-2level/auto/Encode/Encode.bundle' (no such file), '/Library/Perl/5.34/darwin-thread-multi-2level/auto/Encode/Encode.bundle' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')) at /System/Library/Perl/5.34/XSLoader.pm line 96. at /Library/Perl/5.34/darwin-thread-multi-2level/Encode.pm line 12.
When I call the script manually from terminal, it runs fine.
Why is Applescript running as X86 on M2?
Under Ventura, desktop wallpaper image names were stored in a sqlite database at ~/Library/Application Support/Dock/desktoppicture.db. This file is no longer being used under Sonoma.
I have a process I built that fetches the desktop image file names and displays them, either as a service, or on the desktop. I do this because I have many photos I've taken, and I like to know which one I'm viewing so I can make edits if necessary. I set these images across five spaces and have them randomly change every hour. I tried using AppleScript but it would not pull the file names.
A few people have pointed me to ~/Library/Application Support/com.apple.wallpaper/Store/Index.plist. However, on my system, this only reveals the source folder and not the image name itself. On one of my Macs, it shows 64 items, even though I have only five spaces!
Is there a way to fetch the image file names under Sonoma? Will Sequoia make this easier or harder?
Topic:
App & System Services
SubTopic:
General
Tags:
macOS
Photos and Imaging
AppleScript
Files and Storage
I made an application in Script Editor and it works as expected. But the app seems to be getting automatically deleted at random times. For example, I made it a few days ago, tested it successfully, then went back today to look for it and it was gone. Tested this multiple times.
I bit more detail about my process:
I wrote the app in Script editor, exported it as an Application with run-only checked and no code signing
after manipulating a few things (.plist file, .icns file), I then remove extended attributes and code-sign using terminal. I have an Apple developer account that I use to code-sign:
xattr -cr <path_to_app>
codesign -s <my_developer_account> <path_to_app_bundle>
then I copy the app into my Applications folder and test it successfully
a day or more later, the app is gone (and I haven't even opened it again)
Ventura 13.1, Mac Book Pro 2021