Post not yet marked as solved
Platform: macOS 12.3.1
Xcode: 13.3
I had Xcode ARC turned ON.
AppleScript should be declared like below.
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:strScript];
When call AppleScript, open "Monitor.app" app will observe some memory leak.
I try to wrap AppleScript by autoReleasePool. Memery leak still exists
@autoreleasepool {
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:strScript];
//script to do something
}
Is there other suggestion to do gabage collection to release memory?
Post not yet marked as solved
I have a plain text file saved to my Desktop the result of an earlier script. I have a simple AppleScript telling Finder to open the text file:
set open_this to (path to desktop as text) & "Test.txt"
tell application "Finder" to open alias open_this
This results in the error:
"The document "Test.txt" could not be opened. You don't have permission.
To view or change permissions, select the item in the Finder and choose File > Get Info."
Weirdly, if I duplicate the text file and tell Finder to open it I get:
"Finder got an error: Handler can’t handle objects of this class."
I've check permissions on the file and they look normal – my user account has read & write permission.
I have given "Full Disk Access" to Script Debugger, my AppleScript IDE.
This was a known bug in macOS 12.3/12.3.1 and I thought it has been fixed in 12.4 when I tested the beta. But, it is definitely a bug in macOS 12.4.
Does anyone have a way in AppleScript of telling Finder to open a file ?
Post not yet marked as solved
I have an apple script which moves all files within a folder into a new folder according to the first 6 characters of the filenames.
If the folder already exists, the files get moved into that existing folder instead.
If the file already exists in the new/existing folder, the file to be moved into the folder gets a "copy" extension to the filename – which is not in the script, it's a system function ;-)
My question: **Is it possible to move all existing files into a subfolder (named "_alt" for example), before the other files get the "copy"-extension?
**
This is my existing script:
set mgFilesFolder to (choose folder with prompt "Choose folder…")
(* get the files of the mgFilesFolder folder *)
tell application "Finder" to set fileList to files of mgFilesFolder
(* iterate over every file *)
repeat with i from 1 to number of items in fileList
set this_item to item i of fileList
set this_file_Name to name of this_item as string
set thisFileCode to characters 1 thru 6 of this_file_Name as text
log thisFileCode
tell application "Finder"
try
set nf to make new folder at mgFilesFolder with properties {name:thisFileCode}
end try
end tell
end repeat
set sourceFolder to mgFilesFolder
set destinationFolder to mgFilesFolder
tell application "Finder"
set the_files to (get files of mgFilesFolder)
repeat with this_file in the_files
Post not yet marked as solved
I have just installed Xcode 14 Beta but there is no option to make an AppleScript project. Is this no longer available ?
Our application (sandboxed, on the mac) sends Apple Events to itself for being recordable in Script Editor.
Alas, I just noted that this feature stopped working, i.e. at least under macOS 12.4 Script Editor does not see what our application does. I am not sure when (i.e. under what macOS) recordability stopped working, but it is gone on 12.4.
We have tried, (for testing), to set the sandbox exception com.apple.security.temporary-exception.apple-events to true, but it makes no difference.
I know that Apple Script in general, and recordability in particular, are badly out of fashion these days, so we are considering dropping recordability anyway. But if there's an easy way to keep it working, I'd be interested.
Thanks for any advice in advance
I am trying to write an AppleScript to control Orion, a new privacy-focused browser, that will open a new tab in the frontmost window with a specified URL. However, I am getting the result "missing value".
Orion is in beta, and I’m inexperienced with AppleScript, so I can’t tell if the problem is with me or with the browser.
Any help would be appreciated!
What I have now is:
tell application "Orion"
make new tab at window 1 with properties {URL:"https://twitter.com"}
end tell
I have tried variations, listed at the end of this post. Orion does have basic AppleScript support:
Here are the variations I've tried:
tell application "Orion"
tell window 1
make new tab at beginning with properties {URL:"https://twitter.com"}
end tell
end tell
tell application "Orion"
make new tab at end of tabs of window 1 with properties {URL:"https://twitter.com"}
end tell
tell application "Orion" to tell window 1
make new tab with properties {URL:"https://twitter.com"}
end tell
tell application "Orion"
make new document -- maybe this. Creates window
make new tab at end of tabs of window 1 with properties {URL:"https://twitter.com"}
end tell
Post not yet marked as solved
I am trying to get the title of the slides.
But it is not working with apple script, can anyone please help me with this?
This is the code I have written in AppleScript.
tell application "Keynote"
activate
tell the first slide
set slideone to first slide of document 1
set mytitlename to title of slideone
end tell
end tell
Post not yet marked as solved
I have a simple ApplScript which I have decided to put into a User Interface.
In Xcode, I have made an AppleScript project and started to copy the code from the AppleScript into Xcode.
From a button I have the following code
on btnFolderClick_(sender)
set theFolderPath to (choose folder with prompt "Choose The Folder With Scans")
#Count Number Of Images in Folder
tell application "Finder"
set numberOfImages to number of files in folder (((theFolderPath)))
end tell
end btnFolderClick_
When I Run it, I am getting the following error...
-[AppDelegate btnFolderClick:]: Not authorized to send Apple events to Finder. (error -1743)
I sort of understand the error but not sure how to proceed.
Can anyone offer any solution please.
Thank You
Post not yet marked as solved
Hi All,
I'm looking to execute some application installation in silent mode.
Currently, the main issue is avoiding macOS user password prompt by pop-up dialogs with the user's password.
The main idea (of the solution, I suggest) - is providing a macOS username & password as script parameters (inside the script).
I've tried several ways including AppleScript usage, based on providing a username & password, and "with administrator privileges"...
Also - AppleScript usage, based on application run (like: tell application "Terminal")...
Tried - shell scripts...
No success!
Not sure if I'm doing this is correct enough, or if the selected solution is correct at all.
The maximum that I've got: is silent execution stuck (all over attempts - pop the user password dialog).
Thanks a lot!
Trying to create a "master" string containing results from other strings. But sometimes the strings are undefined because they weren't selected as an option.
I tried else if... is not equal to... but that didn't work.
Im trying to avoid having to write out every possible combination. Heres the current script.
Post not yet marked as solved
Hi,
I have tried several tools to send Bluetooth Low Energy (BLE) signals to an external device (e.g. BlueSee BLE Debugger or BSE32 BLE Terminal from the App Store).
Unfortunately, I have not found a way to access these tools via command line.
So I wondered, if sending Bluetooth signals is maybe even possible via command line without additional apps? Or if anyone knows a tool which I could use.
Thank you very much in advance!
Post not yet marked as solved
I used this script to automatically save attachments of some incoming messages in apple mail. Sine Monterey, this doesn't work anymore. Syntax check gives no errors, but in my mail rules the script doesn't run at all.
I did a lot of research to find a solution, with no success.
Any help is appreciated.
Marcus
This is the code …
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
-- set up the attachment folder path
tell application "Finder"
set folderName to "WebApp-Beiträge Mail"
set attachmentsFolder to ("Volumes:Daten HD:Workspace:Universität_Saarland:projekte_Universität_Saarland:2070_uni_2101_WebDev_WebApp:struktur_text_navigation_2070:Beiträge:" & folderName) as text
end tell
tell application "Mail"
repeat with eachMessage in theMessages
--set the sub folder for the attachments to the senders mail address.
-- All future attachments from this sender will the be put here.
set subFolder to (extract address from reply to of eachMessage)
-- set up the folder name for this mail message's attachments. We use the time stamp of the date received time stamp
set {year:y, month:m, day:d, hours:h, minutes:min} to eachMessage's date received
--set timeStamp to (y & "-" & my pad(d) & "-" & my pad(m as integer) & "_" & my pad(h) & "-" & my pad(min)) as string -- month as number
set timeStamp to (y & "-" & my pad(m as integer) & "-" & my pad(d) & "_" & my pad(h) & "-" & my pad(min)) as string -- month as number yyy-mm-dd
--set timeStamp to (y & "_" & my pad(d) & "-" & m & "_" & my pad(h) & "-" & my pad(min)) as string
set attachCount to count of (mail attachments of eachMessage)
if attachCount is not equal to 0 then
-- use the unix /bin/test command to test if the timeStamp folder exists. if not then create it and any intermediate directories as required
if (do shell script "/bin/test -e " & quoted form of ((POSIX path of attachmentsFolder) & "/" & subFolder & "/" & timeStamp) & " ; echo $?") is "1" then
-- 1 is false
do shell script "/bin/mkdir -p " & quoted form of ((POSIX path of attachmentsFolder) & "/" & subFolder & "/" & timeStamp)
end if
try
-- Save the attachment
repeat with theAttachment in eachMessage's mail attachments
set originalName to name of theAttachment
set savePath to attachmentsFolder & ":" & subFolder & ":" & timeStamp & ":" & originalName
try
save theAttachment in file (savePath)
end try
end repeat
--on error msg
--display dialog msg
end try
end if
end repeat
end tell
end perform mail action with messages
end using terms from
on pad(n)
return text -2 thru -1 of ("0" & n)
end pad
Post not yet marked as solved
Hello
The notarization of my AppleScript App fails.
i created a AppleScript Application with the Script Editor.
i exported and signed the app with my Developer ID Application certificate.
Created the *dmg installer:
`hdiutil create -volname AppName -srcfolder /pathToApp -ov -format UDBZ NameOfApp.dmg
`
signed the installer with cmd command:
codesign -s "Developer ID Application: [DevName] (id)" --timestamp NameOfApp.dmg
startet the notarization in the cmd with:
xcrun altool --notarize-app --primary-bundle-id "My-id" -u "[uerName]" -p "[pw]" -t osx -f /pathTo/NameOfApp.dmg
The result is that the notarization fails. has anybody an idea where i can proceed?
Lorenzo
Post not yet marked as solved
Hello,
In my company, we want to connect home user folder automatically in one click, without need to go in Finder/Go/Connect to, etc.
For that we want to push on Mac an Applescript in the form of an application with VMWare WorkSpace One.
In this script is filled in the path of network shared folder. The name of the shared folder is identical to the Mac user session (AD identifier), and therefore specific to each user. The command in the script is this: mount volume "SMB://server/data/users/~[username]"
The variable ~[username] is not recognized.
This script works with a fixed network path.
Which variable could I use?
Or maybe my script is to simple and I need to set the user variable before.
As I am a newbie in Apple Script, I need an help.
I hope to be clear enough.
Thank for your help.
Br,
Post not yet marked as solved
Hello I am using 2 mac pros with both Monterrey 12.4. and using magic mouse and magic keyboard.
Lets name Macpro A and Macpro B, Macpro A has bluetooth connection to magic mouse and keyboard and I am able to use Universal Control seamlessly across both devices from my bt keyboard/mouse.
On macpro B, I have an applescript that opens an application and input 2 strings, each string in a text field using keystroke. The string with special characters gets truncated when applesript tries to write the stirng to the text field. For example, the string "YrR#truT0fmuD$123'45" will get truncated to "YrR#t"
The truncation is very inconsistent but I discovered that if I run the same script on macpro A, it works fine and when Universal control is off then it also works fine.
My example script is below, i've removed the application name
on run argv
-- Launch myapplication.app
activate application "myapplication"
tell application "System Events"
-- Wait until it launches
repeat until (exists window "My Application" of application process "JavaApplicationStub")
delay 1
end repeat
delay 1
-- proccess
tell application process "JavaApplicationStub"
-- window of the process
tell window "My Application"
-- enter name
set focused of text field 1 to true
keystroke "a" using command down
keystroke (item 1 of argv)
-- enter lastname
set focused of text field 2 to true
keystroke "a" using command down
keystroke (item 2 of argv)
-- click Login
# click button 5
end tell
end tell
end tell
end run
Post not yet marked as solved
I would like to be able to get either the key code or the characters/text from an NSEvent/KeyEvent. Absolutely no idea how to do this as the documentation I have found so far has been very limited. I believe I need to create an instance of NSEvent but I do not know how.
My script is below. I am working on a speedrun macro for Minecraft.
This script is fully functioning as is, but currently all it does is check if the control key has been pressed via checking the modifier flags of NSEvent.
use framework "AppKit"
use scripting additions
global ca
set ca to current application
# you may change the following variables
global seed
set seed to "8398967436125155523"
# do not change anything below this line
to isModifierPressed(modifier)
((ca's NSEvent's modifierFlags()) / modifier as integer) mod 2 is equal to 1
end isModifierPressed
repeat
if isModifierPressed(ca's NSEventModifierFlagControl) then execute()
delay 0.01
end repeat
on execute()
tell application "System Events"
delay 0.1
keystroke tab
delay 0.02
keystroke return
delay 0.02
repeat 3 times
keystroke tab
delay 0.02
end repeat
keystroke return
delay 0.02
repeat 2 times
keystroke tab
delay 0.02
end repeat
repeat 3 times
keystroke return
delay 0.02
end repeat
repeat 4 times
keystroke tab
delay 0.02
end repeat
keystroke return
delay 0.02
repeat 3 times
keystroke tab
delay 0.02
end repeat
keystroke seed
delay 0.02
repeat 6 times
keystroke tab
delay 0.02
end repeat
keystroke return
end tell
end execute
Post not yet marked as solved
do shell script quoted form of "~/ddsds.app/Contents/MacOS/ddsd" with administrator privileges
App is not responding, it is launched ie Finder icon is shown but UI is not shown.
if (!SMJobSubmit(kSMDomainSystemLaunchd, (__bridge CFDictionaryRef)job, m_auth, &error))
App is not responding, it is launched ie Finder icon is shown but UI is not shown.
Same piece of code works on BigSur and Monterey
Post marked as Apple Recommended
I created an app that uses AppleScript to automatically convert .numbers files to .csv by opening it in Numbers and using the Export function.
After one of the recent updates¹, in Xcode 11.5 (macOS 10.15.5) this no longer works. It shows the error:
osacompile: no such component "AppleScript".
I get the same error when I manually run the osacompile command in Terminal.
¹The last time I successfully compiled it was on 15 October 2019, so I was already running Catalina, but I don't know which of the updates since then broke it.
How to reproduce
Even without a valid test.applescript file, this is an easy way to reproduce it:
/usr/bin/osacompile -l AppleScript -d -o test.scpt test.applescript
This command gives me the same error.
A simple way to reproduce it in Xcode is to create a new project and make it an AppleScript App.
It can also be reproduced by using this project:
https://github.com/hhas/Swift-AppleScriptObjC
It's impossible to compile now.
Can anyone confirm if this is a bug in macOS / Xcode or just on my system?
Post not yet marked as solved
I am trying to get a workflow in Automator.
I recorded action via "Watch Me Do". And when I replayed, it works well.
When I dragged the action into AppleScript editor, it does not work anymore.
Screenshots :
All I want is to have something that works for commune_1 and edit the script to do the same actions for commune_2, commune_3 and so on.
I have path /private/tmp/test.txt, need to convert it into POSIX file (I need just convert "/private/tmp/test .txt" to "StartUpDisk:private:var:tmp:test.txt)". Can I do it?
Thanks :)
It's application, written on AppleScript using Script Editor