Scripting

RSS for tag

Scripting allows you to automate complex, repetitive, and time-consuming tasks by writing scripts that interact with apps, processes, and the operating system.

Posts under Scripting tag

29 Posts
Sort by:
Post not yet marked as solved
0 Replies
421 Views
Does anyone have a simple example for a scriptable App in Swift in Xcode for macOS? I mean one that exposes objects and functions to applescript? I've checked all examples that I could find. But for me they get me confused about whether they are accessing the actual and already existing instance of a class or whether they are creating an instance with AppleScript, or just using the class definition to call some function. Also the way they are defined in the .sdef file does not help. It would be great if someone had a really simple example, stripped down to bare minimum that 1) defines a class with a single function, 2) creates an instance of the class inside appDelegate and then 3) the function of the specific instance is called using appleScript. 4) It would be great if the function could do something in the GUI, such as change a text of a Label.
Posted
by
Post not yet marked as solved
2 Replies
297 Views
I am trying to automate a backup terminal script to mirror some directories to my NAS. The terminal script is working fine, so I want to automate them. The recommended path uses the launchctl agent, which, from the description, should be what I need. However, I have been running into two errors and looking for answers. I am using a M1 Mac mini with 8GB of memory (for reference). First, I get an error 23, which means too many files are open. If I reboot the machine, this error goes away. But why am I getting this message? I can run the script manually without a problem, and the system is running fine. The machine does little, so it should have almost nothing open. The second error, once the 23 is cleared, is error 12, cannot allocate memory. The machine is an 8GB machine but is reporting 3GB free. Again, the script runs fine in the terminal. I suspect the problem is the agent, but I am unsure how to diagnose or resolve these issues. I do not want to reboot the machine to run the backup, and so is the agent running under some system constraints that are too limiting. Can I change those limits for the job and make the recommended process to automate work? Any suggestions would be appreciated.
Posted
by
Post not yet marked as solved
0 Replies
386 Views
We have an app that is distributed in our .pkg installer (using pkgbuild and productbuild). Now we need to perform various system checks, eg. minimum macOS version and then continue or abort the installation, based on conditions. When we do that in the pre-install script, it works but the user experience is not what we need. The installation aborts with a generic message. What we want is to show the progress, eg. which checks have failed and why, a link to open the installation log, and to gracefully exit the installation. Is it possible to achieve all this without resorting to writing a custom installation mac app ?
Posted
by
Post not yet marked as solved
1 Replies
279 Views
Hi all. I'm a Software Engineer, but I've never done anything with iPhone. I have wanted to try Scriptable for a while but have not had any ideas, until now. I have a book of quotes - one quote on each page - no pictures or anything to get in the way, just a quote surrounded by white space. Ultimately I would like to set up an API for these quotes, but to do so I must enter them into a database. What I would like to do with Scriptable is to access the camera, take a photo of each quote, run OCR on it, and store it in some way so that I can turn around and automatically feed it into a noSQL database like MongoDB. First question: is this possible with Scriptable? I really don't want to create a whole app, because 1) I have too many things already to keep up on without taking on Swift, whereas Scriptable is basically just JavaScript, right? (I already know JavaScript), and 2) I just want this to be for my personal use. I'm not wanting to create something to put on the app store. I have too many things to do without having to deal with putting an app on the app store. Second Question: if it is possible with Scriptable, can you tell me in general terms an outline of how I would go about it? I am NOT looking for actual code - I want to code it myself. What I mean is, what tools on the iPhone will I need to be accessing, and what steps would I need to do this in? For example, I've come across mention of two things when it comes to recognizing text with an iPhone - Vision and LiveText. Now what I saw for Vision was in the context of Swift documentation. Is that only accessible via Swift? What about LiveText? Can I use that in a Scriptable script? If not, is there some sort of tool that Scriptable scripts can access that will convert the text from an image into text that I can save to eventually load into a database? And what tools would I use to access the camera and to store stuff into memory, and is there a specific section of memory I need to look into to save it? Basically, I just need the names of the things I need to read up on in order to accomplish my task. If I know the tools I need to use and have the Scriptable documentation, I'm pretty sure I can figure out the coding part myself. I appreciate any help on this.
Posted
by
Post not yet marked as solved
0 Replies
207 Views
I read on a webpage I can't cite that the Linux coreutils package at version 8.25 was modified so it, by default, the ls command puts single quotes around file names with spaces in them. Also that the ls -N option and the bash QUOTING_STYLE environment variable when set with the value of "literal" can be used to turn off the new behavior. I want to go the other direction in bash under MacOS. Is there a way to turn on wrapping of file names containing spaces in bash? I like not having to add single quotes all the time to the file names I copy and paste on Linux, so it'd be nice to have the same capability, at least optionally, on my Mac.
Posted
by
Post not yet marked as solved
0 Replies
208 Views
Is anyone familiar with the Sonoma 14.4 update file? I asked LLM to help me write a script to update the recovery partition. It keeps suggesting files that were in the old InstallAssistant.pkg, but Sonoma is different. Is anyone familiar with the Sonoma setup and its file structure? Is there a way to update the recovery partition with the latest OS? Because when I restore my computer back to factory reset, it always restores the macOS which came with the Mac. I have a Mac mini M2. Below is the script I used: #!/bin/bash Function to display an error message and exit function display_error { echo "Error: $1" exit 1 } Path to the directory containing InstallAssistant.pkg pkg_directory="/Users/colinp/Downloads" Check if InstallAssistant.pkg exists in the specified directory if [ ! -f "$pkg_directory/InstallAssistant.pkg" ]; then display_error "InstallAssistant.pkg not found in $pkg_directory." fi echo "InstallAssistant.pkg found in $pkg_directory." Prompt user to continue read -p "Do you want to continue? (y/n): " continue_response if [ "$continue_response" != "y" ]; then echo "Operation aborted by user." exit 0 fi Mount the InstallAssistant disk image echo "Mounting InstallAssistant disk image..." if ! hdiutil attach "$pkg_directory/InstallAssistant.pkg" -noverify -mountpoint /Volumes/InstallAssistant; then display_error "Failed to mount InstallAssistant disk image." fi Prompt user to continue read -p "Do you want to continue? (y/n): " continue_response if [ "$continue_response" != "y" ]; then echo "Operation aborted by user." hdiutil detach /Volumes/InstallAssistant >/dev/null 2>&1 exit 0 fi Find the BaseSystem.dmg within the InstallAssistant disk image basesystem_dmg=$(find /Volumes/InstallAssistant -name "BaseSystem.dmg" -print -quit) Check if BaseSystem.dmg is found if [ -z "$basesystem_dmg" ]; then display_error "BaseSystem.dmg not found within InstallAssistant.pkg." fi echo "BaseSystem.dmg found." Prompt user to continue read -p "Do you want to continue? (y/n): " continue_response if [ "$continue_response" != "y" ]; then echo "Operation aborted by user." hdiutil detach /Volumes/InstallAssistant >/dev/null 2>&1 exit 0 fi Determine the device identifier of the target disk recovery_partition=$(diskutil list | grep "Recovery HD" | awk '{print $NF}') if [ -z "$recovery_partition" ]; then display_error "Recovery partition not found." fi echo "Recovery partition found: $recovery_partition" Prompt user to continue read -p "Do you want to continue? (y/n): " continue_response if [ "$continue_response" != "y" ]; then echo "Operation aborted by user." hdiutil detach /Volumes/InstallAssistant >/dev/null 2>&1 exit 0 fi Unmount the recovery partition echo "Unmounting the recovery partition..." if ! diskutil unmountDisk "$recovery_partition"; then display_error "Failed to unmount the recovery partition." fi Prompt user to continue read -p "Do you want to continue? (y/n): " continue_response if [ "$continue_response" != "y" ]; then echo "Operation aborted by user." hdiutil detach /Volumes/InstallAssistant >/dev/null 2>&1 exit 0 fi Restore BaseSystem.dmg to the recovery partition echo "Updating the recovery partition. This may take a while..." if ! sudo asr restore --source "$basesystem_dmg" --target "$recovery_partition" --erase; then display_error "Failed to update the recovery partition." fi Detach the InstallAssistant disk image echo "Detaching InstallAssistant disk image..." if ! hdiutil detach /Volumes/InstallAssistant >/dev/null 2>&1; then display_error "Failed to detach InstallAssistant disk image." fi echo "Recovery partition update complete. any help is appreciated. Thanks in advance.
Posted
by
Post not yet marked as solved
0 Replies
300 Views
Hi, I'm working on a series of scripts and utilities that process logs and generate pre-composed email reports as a consequence, and wanted to use the open "mailto:address?subject=my subject&body=..." to do so from the scripting. to, cc, bcc, subject, and body are all obvious attributes, but what others are handled? Emails are typically sent from a joint mail address, not the user's primary (default) mail account (but one that is also locally provisioned in Mail.app). So I'd like to force the from=address attribute as well. And the messages should be text/plain, not multipart, and the charset of us-ascii. Where can I find the detailed handling on mailto: URL's in MacOS? RFC-6068 is unfortunately a guideline, and doesn't flesh out many requisites. Thanks
Posted
by
Post not yet marked as solved
0 Replies
107 Views
Hello iOS Developer Community, I hope this message finds you healthy and happy. I am reaching out to seek your expertise and assistance with a particular challenge I’ve encountered while using the Speak Screen and Speak Selection features on iOS. As you may know, these features are incredibly useful for reading text aloud, but they sometimes struggle with the correct pronunciation of homographs—words that are spelled the same but have different meanings and pronunciations. An example of this is the word “live,” which can be pronounced differently based on the context of the sentence. To enhance my user experience, I am looking to input corrections for the pronunciation of “live” in its “happening now” context, such as in “live broadcast” or “live event.” However, the current process requires manual entry for each phrase, which is quite labor-intensive. I am wondering if there is a way to automate or streamline this process, perhaps through a shortcut or script that allows for bulk input of these corrections. Additionally, if anyone has already compiled a list of common phrases with homographs and their correct pronunciations, I would greatly appreciate it if you could share it or guide me on where to find such resources. Your insights and guidance on this matter would be invaluable, and I believe any solutions could benefit not just myself but many other users facing similar issues. Thank you for your time and consideration. I look forward to any suggestions or advice you may have. Best regards, Alec
Posted
by