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
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
I have developed Applescripts on Mojave and exported them as apps for Mac users in my department. These ran as expected. I can run them fine on Catalina on my Mac, but cannot make them available to other Catalina users, despite code signing them. Do I need to go through the notarisation process, use XCode, or some other method to make them available as apps to other Mac users in my department? (They do not need to be made available through the app store.)
Post not yet marked as solved
`set theName to text returned of (display dialog "Please, enter name of your file:" default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue")
set New_script_path to "/Users/" & theUser & "/Library/Application Support/GD Saver/Scripts/" & theName & ".txt"
--I need to create a text file in New_script_path
Post not yet marked as solved
I’m trying to run an AppleScript in my SwiftUI button. But i’m not sure on how to do it? The project is for macOS.
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
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
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
Trying to generate an AppleScript executable for MacOS using Xcode 13 Applescript framework. Right out of the box, the project generated by Xcode has the following difficulty. As shown in the Connections inspector for the "App Delegate" icon, the "App Delegate" does not refer to the AppDelegate.applescript listed in the Project navigator. This results in the inability to connect UI elements to the AppleScript code. A screenshot of the Connections inspector is attached showing the error "AppDelegate does not have an outlet named theWindow" whereas the script clearly defines such an outlet. This project is freshly generated, no changes have been made. Am I missing a configuration piece or something else? Examples I've watched on YouTube of generating simple "Hello World" apps all work as the Xcode IB does normally i.e., by using control-drag to contact different objects, but they were all done on earlier versions of Xcode.
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
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.
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
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
Post not yet marked as solved
Hi,
I'm working on an app based on the ITLibrary so I can get all the tracks info like their persistent ID and I'd like to play it in Music from my app.
I do it easily with AppleScript so do I need to use a bridge or can I do it directly from a Swift 4 app ?
Thx.
Post not yet marked as solved
Hello!
I made an AppleScript that uses variables that changes by 1 every second, in the original version, it just tells System Events to type, but I kept getting errors so I changed it to tell System Events to activate and type something. The code works, but on the lines of code that tell System Events to activate, at a random time I get an error saying System Events is not running on the line of code telling it to activate. I am very confused. I will attach the error message as well as the code. The code is from a friend, I am just posting it for him.
Script Error Application isn't running
tell application "System Events" to activate
tell application "System Events" to activate
set beg to 0
set mc to 0
set hour to 0
set search to 0
set pet to 0
set hl to 0
set ud to 0
set pm to 0
set ud to 0
set searchresult to 0
set listhl to {"h", "l"}
set listpm to {"f", "k"}
set listsearch to {"north pole", "advent calendar", "mistletoe", "christmas tree", "christmas card"}
delay 1
set ud to some item of listhl
set pm to some item of listpm
set searchresult to some item of listsearch
set reset to 0
delay 9
tell application "System Events"
keystroke "pls daily"
key code 36
delay 0.5
keystroke "pls beg"
key code 36
delay 0.5
keystroke "pls hunt"
key code 36
delay 0.5
keystroke "pls fish"
key code 36
delay 1
keystroke "pls hl"
key code 36
delay 2
keystroke ud
key code 36
delay 2
keystroke "pls pm"
key code 36
delay 2
keystroke pm
key code 36
delay 2
keystroke "pls search"
key code 36
delay 1
keystroke searchresult
key code 36
set ud to 0
set pm to 0
set searchresult to 0
delay 1
set ud to some item of listhl
set pm to some item of listpm
set searchresult to some item of listsearch
repeat
set beg to beg + 1
set mc to mc + 1
set hour to hour + 1
set search to search + 1
set pet to pet + 1
set hl to hl + 1
delay 1
if hl = 22 then
tell application "System Events" to activate
tell application "Google Chrome" to activate
tell application "System Events"
set hl to 0
keystroke "pls hl"
key code 36
delay 1
keystroke ud
key code 36
set ud to 0
delay 1
set ud to some item of listhl
end tell
end if
if beg = 47 then
tell application "System Events" to activate
tell application "Google Chrome" to activate
tell application "System Events"
keystroke "pls beg"
key code 36
set beg to 0
end tell
end if
if mc = 62 then
tell application "System Events" to activate
tell application "Google Chrome" to activate
tell application "System Events"
set mc to 0
keystroke "pls hunt"
key code 36
keystroke "pls fish"
key code 36
delay 6
keystroke "pls pm"
key code 36
delay 2
keystroke pm
key code 36
set pm to 0
delay 1
set pm to some item of listpm
end tell
end if
if hour = 3600 then
tell application "System Events" to activate
tell application "Google Chrome" to activate
tell application "System Events"
keystroke "pls hourly"
key code 36
delay 1
keystroke "pls daily"
key code 36
set hour to 0
end tell
end if
if search = 37 then
set search to 0
tell application "System Events" to activate
tell application "Google Chrome" to activate
tell application "System Events"
keystroke "pls search"
key code 36
delay 1
keystroke searchresult
key code 36
set searchresult to 0
delay 1
set searchresult to some item of listsearch
end tell
end if
if pet = 1800 then
set pet to 0
tell application "System Events"
keystroke "pls pet pat"
key code 36
keystroke "pls pet feed"
key code 36
if reset = 50 then
set reset to 0
tell application "System Events" to activate
end if
end tell
end if
end repeat
end tell
end
end
end
end
end
end
Post not yet marked as solved
After upgrading to MacOS 12, Applescript seems to require elevated privileges to execute:
osascript -e 'tell app "Finder" to display dialog "Hello, World!"'
results in:
osascript: can't open default scripting component.
whereas:
sudo osascript -e 'tell app "Finder" to display dialog "Hello, World!"'
outputs:
button returned:OK
Also:
osalang -L
ascr appl cgxervdh ()
jscr appl cgxe-v-h JavaScript (JavaScript)
scpt appl cgxervdh JavaScript (JavaScript)
Whereas:
sudo osalang -L
ascr appl cgxervdh AppleScript (AppleScript.)
jscr appl cgxe-v-h JavaScript (JavaScript)
scpt appl cgxervdh Generic Scripting System (Transparently supports all installed OSA scripting systems.)
I have tried reinstalling the upgrade with no change of behaviour.. I'm now on 12.1, again with no change.
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.