Post not yet marked as solved
Finder allows the user to manually change the default 'Open With' application for a file by going to 'Get Info'.
Is there a way to programmatically do this, for example, with AppleScript, in order to change the default 'Open With' application of specific files?
My use-case is changing default 'Open With' application for files that are in a certain directory. I prefer the user doesn't have to do this manually.
Post not yet marked as solved
I have a parent app that contains a child app in the bundle. The child app uses applescript to trigger some events in the parent app.
Now that I'm preparing for App Store I have sandboxed the apps and I am missing something with the entitlements that I don't understand.
In the parent app I have defined the .sdef and I can dump it with sdef /Applications/Parent.app once installed from TestFlight and I see:
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="Parent">
<suite name="Parent Suite" code="prnt" description="Parent Scripts">
<command name="is_first_run" code="prntisfr" description="Is this the first time running the app?">
<cocoa class="MyScriptInterface"/>
</command>
<command name="activation_complete" code="prntWRac" description="Activation is complete">
<cocoa class="MyScriptInterface"/>
</command>
<command name="sign_out" code="prntWRso" description="Sign out and delete local credentials">
<cocoa class="MyScriptInterface"/>
</command>
<command name="get_version" code="prntgetv">
<cocoa class="MyScriptInterface"/>
<direct-parameter type="text" description="None"/>
<result type="text"/>
</command>
</suite>
</dictionary>
In the parent app I have the following included in the .plist:
<key>NSAppleEventsUsageDescription</key>
<string>AppleEvents needed to communicate between components</string>
<key>NSAppleScriptEnabled</key>
<true/>
<key>OSAScriptingDefinition</key>
<string>Parent.sdef</string>
In the Parent entitlements I include the following key parts:
<key>com.apple.security.automation.apple-events</key>
<true/>
<key>com.apple.security.scripting-targets</key>
<dict>
<key>com.foo.parent</key>
<array>
<string>com.foo.parent.is_first_run</string>
<string>com.foo.parent.activation_complete</string>
<string>com.foo.parent.sign_out</string>
<string>com.foo.parent.get_version</string>
</array>
<key>com.foo.parent.child</key>
<array>
<string>com.foo.parent.is_first_run</string>
<string>com.foo.parent.activation_complete</string>
<string>com.foo.parent.sign_out</string>
<string>com.foo.parent.get_version</string>
</array>
</dict>
In the Child app I have only this key:
<key>NSAppleScriptEnabled</key>
<true/>
And in the Child entitlements I have only this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.inherit</key>
<true/>
</dict>
</plist>
I am not getting something. When I install the app and watch Console output I see a combination of errors:
For the Parent app:
AppleEvents/sandbox: Returning errAEPrivilegeError/-10004 and denying dispatch of event prnt/isfr from process '<private>'/0x0-0x7dccdc5, pid=95806, because it is not entitled to send an AppleEvent to this process.
For the Child app from sandboxd:
Violation: deny(1) appleevent-send com.apple.systemevents
MetaData: {"platform-binary":false,"build":"macOS 12.3.1 (21E258)","sandbox_checker":"appleeventsd","process-path":"\/Applications\/Parent.app\/Contents\/MacOS\/Child.app\/Contents\/MacOS\/Child","profile-in-collection":false,"platform_binary":"no","primary-filter-value":"com.apple.systemevents","primary-filter":"appleevent-destination","checker":"appleeventsd","platform-policy":false,"policy-description":"Sandbox","summary":"deny(1) appleevent-send com.apple.systemevents","binary-in-trust-cache":false,"responsible-process-team-id":"367******2","target":"com.apple.systemevents","hardware":"Mac","pid":95806,"appleevent-destination":"com.apple.systemevents","flags":5,"responsible-process-signing-id":"com.foo.parent","apple-internal":false,"normalized_target":["com.apple.systemevents"],"checker-pid":359,"profile-flags":0,"operation":"appleevent-send","errno":1,"action":"deny","uid":501,"responsible-process-path":"\/Applications\/Parent.app\/Contents\/MacOS\/Parent","signing-id":"com.foo.parent.child","team-id":"367******2","container":"\/Users\/spartygw\/Library\/Containers\/com.foo.parent\/Data","process":"Child","release-type":"User"}
Post not yet marked as solved
How do I determine how many columns or rows a Word table cell is spanning?
set theSpan to ___ of cell 1 of text object of table 1
The syntax eludes me. Thanks!
Post not yet marked as solved
Script editor is in some state where it's impossible to compile or run an AppleScript.
The preferences page refuses to allow selecting a Default Language, which I guess is why it won't do anything else. The shortcuts for Compile and Run are greyed out in the menu items.
After jumping thru some security hoops it was possible to run a script with osascript but it's pretty hard to develop applescripts without script editor.
Issue present on OS 12.2.? and 12.3.1
Post not yet marked as solved
Hey All
I need to link these two code snippets together, unable to figure out the best way of doing it
End result would read the XML, select composition and select track then create cues using the first code snippet using the keyframe data (specifically time and value)
Code to add to run for each keyframe of the selected track using keyframe value and time
repeat for all keyframes from the selected track in composition
tell application id "com.figure53.QLab.4" to tell front workspace
make type "Network"
set theNetwork to last item of (selected as list)
set patch of theNetwork to userPatch
set osc message type of theNetwork to custom
set custom message of theNetwork to (keyFrameValue)
set pre wait of theNetwork to (keyFrameTime / 60)
end tell
end repeat
Code to find in XML correct composition, track and keyframe
on run -- example
set XMLfile to (choose file) as text
tell application "System Events" to set rootElement to XML element 1 of contents of XML file XMLfile
set compSelection to (chooseItem from {} out of rootElement) -- compositions list
set trackSelection to (chooseItem from "tracks" out of compSelection)
set frameSelection to (chooseItem from "keyframes" out of trackSelection given tag:"time")
return (getElement for "value" from frameSelection)
end run
# Choose an item from a list - returns the object specifier of the choice.
# The value of the given tag (or index if empty) is used as an entry in the choice dialog.
to chooseItem from listElement out of baseElement given tag:tag : "name"
set elements to (getElement for listElement from baseElement)
set {choices, itemIndex} to {{}, 1}
repeat with anItem in elements
if tag is in {{}, "", missing value} then -- index
set end of choices to (itemIndex as text)
set itemIndex to itemIndex + 1
else -- tag
tell application "System Events" to set end of choices to value of XML element tag of anItem
end if
end repeat
set theResult to (matchChoice from choices into elements given title:"Testing")
if theResult is false then error number -128 -- cancel
return theResult
end chooseItem
# Get an XML element for the specified element or element hierarchy list (use index for list items).
# Returns the element value if it has one; returns all elements if the hierarchyList is empty.
to getElement for hierarchyList from baseElement
try
tell application "System Events"
if hierarchyList is in {{}, "", missing value} then return XML elements of baseElement -- all
set element to baseElement -- starting point
repeat with anItem in (hierarchyList as list) -- build element hierarchy
try
set anItem to anItem as integer -- index?
end try
set element to (get XML element anItem of element)
end repeat
tell (get value of element) to if it is not missing value then return it -- value
return XML elements of element -- object specifier
end tell
on error errmess number errnum -- element not found, etc
error "getElement handler error " & errnum & ":" & return & errmess
end try
end getElement
# Match choice(s) from one list into another.
# The choiceList contains items for use in the dialog, the matchList can be anything.
to matchChoice from choiceList into matchList given prompt:prompt : "", title:title : "", OKButton:OKButton : "OK", multipleItems:multipleItems : false
if matchList is {} or (count choiceList) > (count matchList) then return false -- can't match
set {dialogList, outputList, prefix} to {{}, {}, ""}
set {spacer, divider} to {character id 8203, character id 8204} -- zero width space and non-joiner
repeat with anItem in choiceList -- add indexing prefix to allow duplicates
set prefix to prefix & spacer
set the end of dialogList to (prefix & divider & anItem)
end repeat
set choices to (choose from list dialogList with title title with prompt prompt OK button name OKButton multiple selections allowed multipleItems)
if choices is not false then -- not "Cancel"
repeat with anItem in choices
set indx to (offset of spacer & divider in anItem) -- indexing characters
set the end of outputList to contents of item indx of matchList
end repeat
if not multipleItems then return first item of outputList
return outputList
end if
return false
end matchChoice
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?
I want to receive an incoming file (for example, if the file is opened through my application) and store it in a variable. Can it be done?
Post not yet marked as solved
Hello,
This simple Applescript
tell application "Finder"
open file "a907.jpg" of folder "Photoshopped" of folder "CalBodfish" of folder "Users" of disk "Macintosh HD"
end tell
results in an error that says
The file "a907.jpg" couldn't be opened because you don't have permission to view it. To view or change permissions, select the item in the Finder and choose File > Get Info.
This script worked as expected in previous versions of macos, at least thru 12.0.
If the file is opened by double-clicking on it, the Applescript works as expected, for that particular file.
Much obliged if anyone here can help.
Post not yet marked as solved
We have a problem with curl. Under Big Sur, the command
curl 'ftp://ftp.myserver/myPath/my File' -u 'myusername':'mypassword'
properly downloads the file.
Under Monterey, the same command throws an error:
curl: (3) URL using bad/illegal format or missing URL
Any advice, workaround etc. is highly appreciated.
The behaviour is the same, whether the command is issued in Terminal, or as a shell script in a Applescript application created in XCode.
Post not yet marked as solved
Hi, I'm trying to use apple script below:
tell application "Safari"
activate
tell application "System Events"
tell process "Safari"
set frontmost to true
click menu item "Google Chrome.app…" of menu of menu item "Import From" of menu "File" of menu bar 1
end tell
end tell
end tell
But it says "System Events got an error: Can’t get menu item "Google Chrome.app…" of menu of menu item "Import From" of menu "File" of menu bar 1 of process "Safari"." Error
I have no idea what's wrong with this script. Please give me any advice. Thanks.
Post not yet marked as solved
In MAC, while interacting to the MS Power Point with the AppleScript, I can't access to the 'Paste Special with Style Text' drop down selection, please guide on this topic.
Note: paste text to first presentation with first frame
tell application "Microsoft PowerPoint"
open alias "Untitled:Selvam:PPT_2022:Cross-sectional-Group-Session_CR_for_Session_909.pptx"
end tell
delay 2
tell application "Microsoft PowerPoint"
activate
tell slide 1 of active presentation
set content of text range of text frame of shape 1 to " "
tell application "System Events"
keystroke "v" using {command down}
tell application process "Microsoft PowerPoint"
--tell menu 4 of menu bar 1
-- tell menu item 12 to click
--end tell
keystroke "v" using {command down}
end tell
end tell
end tell
end tell
Thanks,
Selva
My AppleScript applet has a user guide in its resources folder. The guide is in PDF format. To show the guide, my applet has this code:
set path_to_Applet_alias to path to me as alias
set help_file to (path to resource "Help.pdf" in bundle path_to_Applet_alias) as string
tell application "Finder"
open file help_file
end tell
That code works. The applet is localised for a few languages. When I set the language in my applet to another language, e.g. French, that code punches an error:
"The application "Preview" can't be opened" -1703
According to Apple, the "-1703" error means "The wrong data type was detected". But, the data type hasn't changed.
I suspect something is going on with the translation but, I can't figure out what.
Any ideas ?
Post not yet marked as solved
Hi everyone. I need your help. I‘m trying to rename multiple files that have a pattern like :
AJTHGH-BK-48367.jpg
AJTHGH-BK-48368.jpg
AJTHGH-BK-48369.jpg
AJTHGH-BK-48370.jpg
that needs to be renamed into :
AJTHGH-BK-1.jpg
AJTHGH-BK-2.jpg
AJTHGH-BK-3.jpg
AJTHGH-BK-4.jpg
so instead of 5 digits i need to use 1,2,3,4,5… but pay attention on the filenames.
hope that make sense. I gave 3 examples…
Post not yet marked as solved
Good evening everyone. I created a program in AppleScript. In this script, there are keystroke and key code. When the program runs a forbidden access message appears. I authorized the program in Accessible. But nothing is done. What's going on? How to solve this problem. Thank you in advance.
Post not yet marked as solved
Since 12.2, network preferences does not return VPN connections anymore. Therefore, VPN autoconnect scripts / Applications do not work anymore.
tell application "System Events"
tell current location of network preferences
name of every service
end tell
end tell
Returns:
{"USB 10/100/1000 LAN", "WLAN", "iPhone-USB", "Thunderbolt Bridge"}
Has the API changed?
Post not yet marked as solved
The following script contains an error that appears when I compile it. Any help would be appreciated.
Returns a link to the first selected Apple Mail message
*)
tell application "Mail"
set _msgs to selected messages of message viewer 0
if (_msgs is not equal to missing value) then
set _msg to first item of _msgs
set _msgID to do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & (message id of _msg)
return "message://%3C" & (_msgID) & "%3E"
end if
end tell
Many thanks ahead of time.
My AppleScript applet is localized for French, German, Italian and Spanish. The applet displays text in the correct language if the preferred language is changed in the "General" pane of the Language & Region preferences. That is, the applet correctly works in all four languages.
However, the "Apps" pane shows Spanish, German and Italian but, does not show French. For example:
Why would the "Apps" pane not show all languages for which the applet is localized ?
Thanks
late 2015 iMac 27", macOS 12.2.1
Post not yet marked as solved
Hello,
I created a small Apple Script that displays a dialog window containing a reminder message.
set theDialogText to "PLEASE TURN OFF THE UPS AFTER COMPUTER SHUTDOWN!!"
display dialog theDialogText with title "!!!!!!WARNING!!!!!!"
Is there a way to make this dialog window appear before the shutdown of my mac mini M1 (Monterey 12.2.1)? On the bind of the shutdown button for example?
The user must click on the dialog window OK button to confirm that he has seen the message.
Thank you
Post not yet marked as solved
Hello everyone. I created a program that uses "System Events" and I have lots of error messages when it "runs". Two error messages 1): "is not allowed to send keystrokes." and 2): "is not allowed to send keystrokes", is displayed when the program uses "keystrokes" or "key code" with "System Events". I have authorized the AppleScript program in the "Security and Privacy" section and error messages always appear. How to solve this problem? Thank you in advance.
Post not yet marked as solved
Good evening everyone. I can't run a line of JavaScript in AppleScript. Is that normal? It's normal? Thank you in advance.