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
120 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 Last updated
.
Post not yet marked as solved
3 Replies
768 Views
Hi, not sure if this forum is the right place to ask, but it’s extremely difficult to search the web for answers about shortcuts.app (must be the name…). I’m learning python currently and I’m trying to automate recurring tasks on my Mac easily. I have a python script as a first test-case that works (It basically makes a bunch of named folders). I use Apples Shortcuts.app to execute the python-file with the shell-script action. I start this script in Finder from the Quick Actions menu. The script creates my folders, but not in the selected folder when executing it, but always in my users home folder /Users/markus/. I suspect I have to somehow tell the Shortcut to take the currently selected folder as a variable or something. I tried to read the help but I don’t find anything useful and don’t understand the options of the Shell-Script Action in Shortcuts.app. Any ideas how I can get this to work? Or does anyone have a link to a good forum to ask questions about Shortcuts.app and automation? Thanks! Regards Markus
Posted
by M_Ceh.
Last updated
.
Post not yet marked as solved
0 Replies
97 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 cjpowis.
Last updated
.
Post not yet marked as solved
0 Replies
101 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 Last updated
.
Post not yet marked as solved
1 Replies
173 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 apex2020.
Last updated
.
Post not yet marked as solved
0 Replies
274 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 Last updated
.
Post not yet marked as solved
2 Replies
207 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 CodeSolve.
Last updated
.
Post not yet marked as solved
0 Replies
331 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 Stan1.
Last updated
.
Post not yet marked as solved
2 Replies
882 Views
I am working on a Unity IOS game. I keep getting this reoccurring issue. I downloaded XCODE via the app store, so it automatically is in my applications folder Here is the log: Showing Recent Messages WorkingDir: /Users/parkerbrandt/Library/Developer/Xcode/DerivedData/Unity-iPhone-gsxoxmhunhavroeddecygwafmdgn/Build/Intermediates.noindex/Unity-iPhone.build/ReleaseForRunning-iphoneos/artifacts/arm64/buildstate ExitCode: 4 Duration: 0s13ms ExitCode: 1 Duration: 0s1ms Build failed with 0 successful nodes and 0 failed ones Error: Internal build system error. BuildProgram exited with code 1. Unity.IL2CPP.Bee.BuildLogic.ToolchainNotFoundException: IL2CPP C++ code builder is unable to build C++ code. In order to build C++ code for Mac, you must have Xcode installed. Building for Apple Silicon requires Xcode 9.4 and Mac 10.12 SDK. Xcode needs to be installed in the /Applications directory and have a name matching Xcode*.app. Or be selected using xcode-select. It's also possible to use /Library/Developer/CommandLineTools if those match the listed requirements. More information and installation instructions can be found here: https://developer.apple.com/support/xcode/ Specific Xcode versions can be downloaded here: https://developer.apple.com/download/more/ Unable to detect any compatible iPhoneOS SDK! at Unity.IL2CPP.Bee.BuildLogic.iOS.iOSBuildLogic.GetCompatibleXcodeInstallation(Architecture architecture, Version xcodeMinVersion, Version platformSdkMinVersion, Identifier platformSdkIdentifier, XcodePlatformSdk& compatiblePlatformSdk, XcodeInstallation& compatibleXcodeInstallation) at Unity.IL2CPP.Bee.BuildLogic.iOS.iOSBuildLogic.UserAvailableToolchainFor(Architecture architecture, NPath toolChainPath, NPath sysRootPath) at Unity.IL2CPP.Bee.IL2CPPExeCompileCppBuildProgram.BuildProgram.Main(String[] args, String currentDirectory) at Unity.IL2CPP.Building.InProcessBuildProgram.StartImpl(String workingDirectory, String[] arguments) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP.Building/InProcessBuildProgram.cs:line 51 Error: Unity.IL2CPP.Building.BuilderFailedException: Build failed with 0 successful nodes and 0 failed ones Error: Internal build system error. BuildProgram exited with code 1. Unity.IL2CPP.Bee.BuildLogic.ToolchainNotFoundException: IL2CPP C++ code builder is unable to build C++ code. In order to build C++ code for Mac, you must have Xcode installed. Building for Apple Silicon requires Xcode 9.4 and Mac 10.12 SDK. Xcode needs to be installed in the /Applications directory and have a name matching Xcode*.app. Or be selected using xcode-select. It's also possible to use /Library/Developer/CommandLineTools if those match the listed requirements. More information and installation instructions can be found here: https://developer.apple.com/support/xcode/ Specific Xcode versions can be downloaded here: https://developer.apple.com/download/more/ Unable to detect any compatible iPhoneOS SDK! at Unity.IL2CPP.Bee.BuildLogic.iOS.iOSBuildLogic.GetCompatibleXcodeInstallation(Architecture architecture, Version xcodeMinVersion, Version platformSdkMinVersion, Identifier platformSdkIdentifier, XcodePlatformSdk& compatiblePlatformSdk, XcodeInstallation& compatibleXcodeInstallation) at Unity.IL2CPP.Bee.BuildLogic.iOS.iOSBuildLogic.UserAvailableToolchainFor(Architecture architecture, NPath toolChainPath, NPath sysRootPath) at Unity.IL2CPP.Bee.IL2CPPExeCompileCppBuildProgram.BuildProgram.Main(String[] args, String currentDirectory) at Unity.IL2CPP.Building.InProcessBuildProgram.StartImpl(String workingDirectory, String[] arguments) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP.Building/InProcessBuildProgram.cs:line 51 at il2cpp.Program.DoRun(TinyProfiler2 tinyProfiler, String[] args, RuntimePlatform platform, Il2CppCommandLineArguments il2CppCommandLineArguments, BuildingOptions buildingOptions, Boolean throwExceptions) in /Users/bokken/build/output/unity/il2cpp/il2cpp/Program.cs:line 319 Command PhaseScriptExecution failed with a nonzero exit code
Posted Last updated
.
Post not yet marked as solved
2 Replies
2.1k Views
Hello, i am currently trying to implement a pre build script execution in a package. I am using this tutorial to implement it. But it only shows how to use the pre build feature with an already existing feature. I want to execute a skript on my pc every time i build the project. I can't use apples prebuild skript feature in the build settings because it is a package. Right now my code looks like this: import Foundation import OSLog import PackagePlugin @main struct GenerateLocalizer: BuildToolPlugin {     do {       let commandlineOutput = try shell("./testScript.sh")     } catch {     }     return [.prebuildCommand(displayName: "Generate Strings", executable: PackagePlugin.Path("./scrips/generate_strings.sh"), arguments: [], outputFilesDirectory: target.directory)]   }   func shell(_ command: String) throws -> String {     let task = Process()     let pipe = Pipe()     task.standardOutput = pipe     task.standardError = pipe     task.arguments = [command]     os_log("%{public}@", log: log, task.arguments?.joined(separator: " ") ?? "not found")     task.launchPath = "/bin/zsh"     task.standardInput = nil     try task.run()     let data = pipe.fileHandleForReading.readDataToEndOfFile()     let output = String(data: data, encoding: .utf8)!     return output   } } and my Package file looks something like that       name: "CustomSdk",       dependencies: ["CustomSdk-Objc"],       path: "CustomSdk",       exclude: ["Info.plist", "CustomSdk.podspec"],       plugins: [         .plugin(name: "GenerateLocalizer")       ]     ),     .plugin(name: "GenerateLocalizer",         capability: .buildTool(),         dependencies: ["CustomSdk-Objc"]     ) It gets called properly but when want to write files in my "testScript.sh" it only says: Operation not permitted. Anyone got any ideas how to fix this or is there another way to utitlize custom scripts with custom packages? Greetings Ben
Posted
by benkai.
Last updated
.
Post not yet marked as solved
15 Replies
34k Views
Trying to do a CLI build with XCode (using NativeScript).Was working fine a couple days ago. However, now I cannot get past this error when trying to build:DTDeviceKit: deviceType from 7c64d8a014fd573ca3623ef80b158e57e7aea7c5 was NULL2018-05-07 11:57:54.696 xcodebuild[14808:865317] DVTPortal: Service '<DVTPortalViewDeveloperService: 0x7fe4e17686d0; action='viewDeveloper'>' encountered an unexpected result code from the portal ('1100')2018-05-07 11:57:54.696 xcodebuild[14808:865317] DVTPortal: Error:Error Domain=DVTPortalServiceErrorDomain Code=1100 "Your session has expired. Please log in." UserInfo={payload=<CFBasicHash 0x7fe4e242ed70 [0x7fff9115faf0]>Whenever I open XCode and to go preferences->account, my team account already reports "Session has expired". I log in successfully, then close Xcode, then login again, and once again it says the "Session has expired".Enabled two factor authentication hasn't helped. I get the identical error from two separate machines (Mac Mini and MacBook Air). Using latest High Sierra OS and XCode.My developer accounts logs in fine to the developer portal on Apple's Developer site, iTunes connect, etc..
Posted
by julian87.
Last updated
.
Post marked as Apple Recommended
2.5k Views
I have started to experiment with Xcode UI testing and with in my first few tests, I am observing that the app state is being retained between tests.How I kill the app completely?http://masilotti.com/xctest-documentation/Classes/XCUIApplication.html#//api/name/terminatecommand only seems to put the app in background/suspend it
Posted
by smalugu.
Last updated
.
Post not yet marked as solved
1 Replies
390 Views
So nowadays my MacOS software uses an installer (http://s.sudre.free.fr/Software/Packages/about.html Packages) and it is able to correctly install the application. My client needs to have a quiet installer because he needs to install the app in a large number of computers so using the interactive mode is not good. I am trying to create a script to do that but I am facing the Read-only file system error. Of course my script runs as root. I tried creating a simple Swift code to check, I got the same. So my question: why an installer such Packages can create the folder into the /System/Applications and copy the required files as it runs at the same level of the script and my test program and them don't have the same permission?
Posted Last updated
.
Post not yet marked as solved
4 Replies
1.1k Views
When running the following AppleScript (other portions were removed for clarity)… set newDate to "1/1/1953 00:00 AM" do shell script "SetFile -d " & quoted form of newDate & " " & quoted form of filePath I can change  the created date to any year from 1970 to 2079 but attempting any year outside that range returns unpredictable results.  For instance, using 1/1/1953, the created date became February 6, 2096. But if I enter 1/1/2096 the created date becomes September 3, 2061. Any year between 1970 and 2079 yields the correct result. So, what’s the workaround? I need to be able set the year to any date from 1920 to the present and SetFile apparently can’t handle that range. 
Posted
by starkadhr.
Last updated
.
Post not yet marked as solved
0 Replies
374 Views
I get the error code: System Events got an error: Can't get application of "Application Name" during this line repeat with currentWindow in every window of application foregroundApp of this code on run tell application "System Events" set foregroundApps to displayed name of (every process whose background only is false) as list repeat with foregroundApp in foregroundApps set appName to foregroundApp as text if exists (window 1 of process appName) then repeat with currentWindow in every window of application foregroundApp end repeat end if end repeat end tell end run I'm guessing I'm missing something like set x to foregroundApp as y repeat with currentWindow in every window of application x How do I get the windows of the application foreground app?
Posted Last updated
.
Post not yet marked as solved
2 Replies
1.7k Views
I have an applescript that works perfectly on my local machine. It opens the file and writes to it and then closes. My Applescript is being tested and saved as a .app so it is an application. When I put the application on my server to test out the user experience it never propely opens the file and gives me this error:"File not open with write permission.Finder got an error: File not open with write permission. (-61)"Why would this work on my local machine and not work after being downloaded from my server? I have tested that my path's are correct and like I mentioned everything works perfectly on my local MAC machine. Here is the section of my Applescript code that seems to be throwing the error:set motionFullPath to ("" & pathEffects & "" & effectPlugin & ":" & theFolders & ":" & motionFiles & "") as string set myFile to open for access file motionFullPath with write permission set endOfFile to (get eof myFile) as number if result > 0 then set theText to read myFile set eof myFile to endOfFile write "<!--uuid:" & theURL & "-->" & return & theText to myFile end if close access myFile
Posted
by Eseyee.
Last updated
.
Post not yet marked as solved
1 Replies
476 Views
We have our own root CA that is installed with our application. For non-MDM installs, the system asks if the user wants to do that, which is all well and good. It also used to ask us when removing that certificate. It doesn't now. So now I am wondering if I dreamed it, except other people say they also got prompted and don't now. It's being installed and removed using the security command, in scripts.
Posted
by kithrup.
Last updated
.
Post not yet marked as solved
2 Replies
2.7k Views
I'm installing texturepacker in ci_post_clone.sh script using below command in Xcode Cloud workflow. ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null ; brew install caskroom/cask/brew-cask 2> /dev/null brew install --cask texturepacker But I'm getting sudo warning in log. ==> Downloading https://www.codeandweb.com/download/texturepacker/6.0.2/TexturePacker-6.0.2.dmg ==> Installing Cask texturepacker sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper sudo: a password is required sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper sudo: a password is required sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper sudo: a password is required sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper sudo: a password is required ==> Purging files for version 6.0.2 of Cask texturepacker Error: Permission denied @ dir_s_mkdir - /usr/local/Caskroom How can i fix this issue? Any idea or suggestions would be appreciated. Thank You
Posted Last updated
.
Post not yet marked as solved
1 Replies
987 Views
Hi all, I am trying to find a way to export the content of a .pages file into .xml format. That can be done saving the file to '09 version and then unzipping and working on the xml file. But I would like to do it also with .iwa files. I am trying to find a workaround to translate pages file on windows platform without need to pass through word extension, or the '09 format (in order to reduce DTP at its minimum). I am coding on Python... Thank you so much for any suggestion!
Posted Last updated
.