Post

Replies

Boosts

Views

Activity

Reply to AppleScript. Split the string into parts by the separator character.
Text item delimiters are what you are looking for, for example: set myString to "MyData1|MyData2" set {myVar1, myVar2} to splitString(myString) to splitString(someString) try set tempTID to AppleScript's text item delimiters -- save current delimiters set AppleScript's text item delimiters to "|" set pieces to text items of someString -- split the string set AppleScript's text item delimiters to tempTID -- restore old delimiters set firstPart to item 1 of pieces set secondPart to item 2 of pieces on error errmess -- delimiter not found log errmess return {firstPart, ""} -- empty string for missing item end try return {firstPart, secondPart} end splitString
Aug ’23
Reply to Speeding Up Code
You can speed it up a bit more by not bothering with the check for a window, as just getting the windows will always return a list and avoid the duplication in getting windows. Better yet, you can usually reduce overhead by having an application do as much as possible with any given call, for example: tell application "System Events" set foregroundApps to (processes whose background only is false) repeat with anApp in foregroundApps set minimizedWindows to (windows of anApp where value of attribute "AXMinimized" is true) repeat with aWindow in minimizedWindows tell aWindow to set value of attribute "AXMinimized" to false end repeat end repeat end tell In this example you can go even further by doing something like getting the (windows of (processes whose background only is false) where value of attribute "AXMinimized" is true), but there are diminishing returns for increased noise and the performance of complex expressions depends a bit on the particular application.
Sep ’23
Reply to translation project only uses first and last items in a Numbers cell range
It is only translating the first and last items because in the getCellRangeValues handler, that is all that the words of cellRange list contains. You would need to get the individual cell elements of the range and use those in the repeat statement to get the in between cell references, for example: repeat with cellRef in cells of range cellRange of tbl set end of cellValues to value of cellRef end repeat
Mar ’24
Reply to AppleScript, Do Shell. How do I write the "test" command to the "script editor"?
This is one of those situations where learning some basics instead of having others do everything helps. The posted script just has some quoting issues - either escape the double quotes for use in the string, or use single quotes since the shell also understands those. The corrected script would be: set myFile to choose file -- choose a package or or try `choose folder` to select a folder set theCommand to "(test -d " & quoted form of POSIX path of myFile & " && echo 'is a dir') || (set status 0; echo 'not a dir') ; 2>&1" return do shell script theCommand
Jun ’24
Reply to Applescript: window API handler crashing in split view
OK, I am getting a few different errors, but the problem seems to be that for whatever reason (looks like a bug), when you initially click in the window or use the divider or history, the window accessibility properties are not getting set up. Clicking the window again gets things set up, but until then the "front" window doesn't have any properties for the script to use, such as selected tab, so trying to use that throws an error. Unfortunately, this also prevents targeting the window by name, id, tty, etc, so I haven't found a workaround other than to click the window a couple of times before running the script. A command line tool to do the clicking could probably be used, but you would need to get information about the "front" window to get the bounds to click into, which would most likely be way more involved than what you are doing now.
Aug ’24
Reply to Applescript text item delimiters not working
The usual approach would be to save whatever the existing delimiters are, set the delimiters to what you want to use, split the string into a list of its text items, restore the previous delimiters, and then just use the list. You are continually splitting the string to get each piece, so all it would take is for the delimiters to get changed/reset somewhere else in the bigger script for the text items to be different the next time you split the string. Another option would be to try using the words of the string.
Topic: Programming Languages SubTopic: General Tags:
Oct ’24
Reply to Shortcuts app in macOS has no logic
Automator and Shortcuts built-in actions are general-purpose in nature, based mostly on existing shell utilities or common functions, or a developer was generous and decided to include some to support their application. There are tiling and window moving scripts out there (various scripting forums, GitHub, etc), but you would need to graft them into your specific workflow (Run AppleScript, Run Shell script, etc). Other options would be to find 3rd-party actions or make your own, although manipulating the UI is a pain no matter what you use.
Oct ’24
Reply to Shortcuts app in macOS has no logic
Actions are designed to perform a specific task, which is usually general-purpose in nature. They do what they do. I don't know what you did before to get windows moved, but your posted sample workflow isn't going to work at all. Take a look at the action info, which specifies what the input and output will be. Opening files returns files (not windows), and the window actions require a window (not an image) to resize or move, which isn't specified anywhere. Also note that there isn't a line connecting the actions, which indicates they aren't compatible (there isn't anything to convert the action's input/output). You would need to do something like open the files in Preview, wait a little bit to let them open, then have the Find Windows action filter for Preview windows. From there, you would need to loop through the windows, resizing and moving as desired, but now you are fighting what Shortcuts was designed to be (like a graphical shell script), and might as well use something more designed for the task, like a 3rd party action or scripting. Shortcuts (and Automator) have their purpose, but they aren't really designed for much beyond batch workflows without some help.
Oct ’24
Reply to AppleScript. Split the string into parts by the separator character.
Text item delimiters are what you are looking for, for example: set myString to "MyData1|MyData2" set {myVar1, myVar2} to splitString(myString) to splitString(someString) try set tempTID to AppleScript's text item delimiters -- save current delimiters set AppleScript's text item delimiters to "|" set pieces to text items of someString -- split the string set AppleScript's text item delimiters to tempTID -- restore old delimiters set firstPart to item 1 of pieces set secondPart to item 2 of pieces on error errmess -- delimiter not found log errmess return {firstPart, ""} -- empty string for missing item end try return {firstPart, secondPart} end splitString
Replies
Boosts
Views
Activity
Aug ’23
Reply to AppleScript Language Guide. open for access. The parameter is not specified in the syntax.
That is the parameter - see the Conventions Used in the Language Guide Introduction.
Replies
Boosts
Views
Activity
Aug ’23
Reply to The hierarchy of content items on the site is changing developer.apple.com
It doesn't do that on any of my systems - could a browser plugin be interfering?
Replies
Boosts
Views
Activity
Aug ’23
Reply to The hierarchy of content items on the site is changing developer.apple.com
This is why I asked if there was a browser plugin or something like that. I have never seen that happen with Safari in any macOS I’ve used, and I also don’t see it with Firefox in Linux. Note that that guide was last updated in 2016.
Replies
Boosts
Views
Activity
Aug ’23
Reply to Speeding Up Code
You can speed it up a bit more by not bothering with the check for a window, as just getting the windows will always return a list and avoid the duplication in getting windows. Better yet, you can usually reduce overhead by having an application do as much as possible with any given call, for example: tell application "System Events" set foregroundApps to (processes whose background only is false) repeat with anApp in foregroundApps set minimizedWindows to (windows of anApp where value of attribute "AXMinimized" is true) repeat with aWindow in minimizedWindows tell aWindow to set value of attribute "AXMinimized" to false end repeat end repeat end tell In this example you can go even further by doing something like getting the (windows of (processes whose background only is false) where value of attribute "AXMinimized" is true), but there are diminishing returns for increased noise and the performance of complex expressions depends a bit on the particular application.
Replies
Boosts
Views
Activity
Sep ’23
Reply to Applescript to estimate driving times
A combination can be used. Shortcuts and Automator both have AppleScript, JavaScript/JXA, and shell script actions, so built-in actions can be used to get results that are then passed to your code. AppleScriptObjC, JXA, and PyObjC can also use (most) Cocoa frameworks.
Replies
Boosts
Views
Activity
Sep ’23
Reply to Access of app to read and write - Administrator cannot change access
Unless that is a typo, the download_folder path is not valid.
Replies
Boosts
Views
Activity
Oct ’23
Reply to translation project only uses first and last items in a Numbers cell range
It is only translating the first and last items because in the getCellRangeValues handler, that is all that the words of cellRange list contains. You would need to get the individual cell elements of the range and use those in the repeat statement to get the in between cell references, for example: repeat with cellRef in cells of range cellRange of tbl set end of cellValues to value of cellRef end repeat
Replies
Boosts
Views
Activity
Mar ’24
Reply to AppleScript, Do Shell. How do I write the "test" command to the "script editor"?
This is one of those situations where learning some basics instead of having others do everything helps. The posted script just has some quoting issues - either escape the double quotes for use in the string, or use single quotes since the shell also understands those. The corrected script would be: set myFile to choose file -- choose a package or or try `choose folder` to select a folder set theCommand to "(test -d " & quoted form of POSIX path of myFile & " && echo 'is a dir') || (set status 0; echo 'not a dir') ; 2>&1" return do shell script theCommand
Replies
Boosts
Views
Activity
Jun ’24
Reply to Applescript: window API handler crashing in split view
If you are talking about the split pane view, your script sample works for me in Sonoma. You mention a handler - is the handler being called differently, such as from another tell statement?
Replies
Boosts
Views
Activity
Aug ’24
Reply to Applescript: window API handler crashing in split view
OK, I am getting a few different errors, but the problem seems to be that for whatever reason (looks like a bug), when you initially click in the window or use the divider or history, the window accessibility properties are not getting set up. Clicking the window again gets things set up, but until then the "front" window doesn't have any properties for the script to use, such as selected tab, so trying to use that throws an error. Unfortunately, this also prevents targeting the window by name, id, tty, etc, so I haven't found a workaround other than to click the window a couple of times before running the script. A command line tool to do the clicking could probably be used, but you would need to get information about the "front" window to get the bounds to click into, which would most likely be way more involved than what you are doing now.
Replies
Boosts
Views
Activity
Aug ’24
Reply to AppleScript: Folder Information
Finder and/or System Events can provide some information (see their scripting dictionaries), and the Cocoa API (via AppleScriptObjC) can use framework methods such as NSURL's getResourceValue. You would need to provide additional details for a more specific answer.
Replies
Boosts
Views
Activity
Aug ’24
Reply to Applescript text item delimiters not working
The usual approach would be to save whatever the existing delimiters are, set the delimiters to what you want to use, split the string into a list of its text items, restore the previous delimiters, and then just use the list. You are continually splitting the string to get each piece, so all it would take is for the delimiters to get changed/reset somewhere else in the bigger script for the text items to be different the next time you split the string. Another option would be to try using the words of the string.
Topic: Programming Languages SubTopic: General Tags:
Replies
Boosts
Views
Activity
Oct ’24
Reply to Shortcuts app in macOS has no logic
Automator and Shortcuts built-in actions are general-purpose in nature, based mostly on existing shell utilities or common functions, or a developer was generous and decided to include some to support their application. There are tiling and window moving scripts out there (various scripting forums, GitHub, etc), but you would need to graft them into your specific workflow (Run AppleScript, Run Shell script, etc). Other options would be to find 3rd-party actions or make your own, although manipulating the UI is a pain no matter what you use.
Replies
Boosts
Views
Activity
Oct ’24
Reply to Shortcuts app in macOS has no logic
Actions are designed to perform a specific task, which is usually general-purpose in nature. They do what they do. I don't know what you did before to get windows moved, but your posted sample workflow isn't going to work at all. Take a look at the action info, which specifies what the input and output will be. Opening files returns files (not windows), and the window actions require a window (not an image) to resize or move, which isn't specified anywhere. Also note that there isn't a line connecting the actions, which indicates they aren't compatible (there isn't anything to convert the action's input/output). You would need to do something like open the files in Preview, wait a little bit to let them open, then have the Find Windows action filter for Preview windows. From there, you would need to loop through the windows, resizing and moving as desired, but now you are fighting what Shortcuts was designed to be (like a graphical shell script), and might as well use something more designed for the task, like a 3rd party action or scripting. Shortcuts (and Automator) have their purpose, but they aren't really designed for much beyond batch workflows without some help.
Replies
Boosts
Views
Activity
Oct ’24