AppleScript

RSS for tag

AppleScript allows users to directly control scriptable Macintosh applications as well as parts of macOS itself.

Posts under AppleScript tag

200 Posts

Post

Replies

Boosts

Views

Activity

AppleScript difference between scpt and app
I have the following Applescript XY.scpt which runs perfect from within the ScriptEditor. But after exporting it to an App (XY.app) it breaks with the message "System Events got an error: XY not allowed assistive access." (-1719)". This is in Ventura 13.3 and the script XY is allowed for Accessibility and Automation in System Settings Security&Privacy. set CR to ASCII character 13 set my0xC9 to ASCII character 201 tell application "Notes" activate set uiScript to "click menu item \"export as pdf" & my0xC9 & "\" of menu 1 of menu bar item \"File\" of menu bar 1 of application process \"Notes\"" run script "tell application \"System Events\" " & CR & uiScript & CR & " end tell" end tell Thanks for your help, ideas and input!
4
0
893
Apr ’23
Select document name Folder inside subfolder
hello, how can we make a script that can open a folder with the name of a pdf document I choose on the desktop and put this pdf in that folder, and also open a subfolder named “incoming” in this folder and put it in the same pdf folder. sorry for my poor English. The script below does the first stage of the scenario I want, what I want after that is to open another folder named “incoming” in the resulting folder and copy the same first document to this folder named “incoming”, at the end of the job, 2 folders inside each other and the document I selected in the first place. It should be, thank you very much. tell application “Finder” activate set selectedFiles to selection as alias list set containingFolder to container of (item 1 of selectedFiles) --as alias repeat with i from 1 to count of selectedFiles set foldersRef to (a reference to folders of containingFolder) set foldersRefItems to name of (contents of foldersRef) set thisItem to item i of selectedFiles set fileName to (text items 1 thru -5) of (name of thisItem as text) as string if fileName is not in foldersRefItems then move thisItem to (make new folder at containingFolder ¬ with properties {name:fileName}) else move thisItem to folder fileName of containingFolder end if end repeat Summary Select Desktop/demo.pdf ———start script Final
0
0
498
Mar ’23
How to use YOLOv3 from applescript
Hello. I would like to compile the YOLOv3.mlmodel for object detection as a framework and call it from applescript to use it, but I do not know how. The flow I am imagining is as follows Import "YOLOv3.mlmodel" on xcode and create a framework. Load the created framework with applescript's use statement and execute it. Please let me know if you know anything about this.
1
0
855
Mar ’23
AppleScript – "text item delimiters" uses non-specified delimiters - FIXED
SOLVED I want to parse some plain text and pull out the 11th and 13th words. I can't get it to work because "text item delimiters" sometimes treats additional characters as delimiters. set test_text to "one two three four five six seven eight nine ten elev-en twelve thir-teen" set AppleScript's text item delimiters to "" set AppleScript's text item delimiters to {" "} set word_11 to word 11 of test_text set word_12 to word 12 of test_text set word_13 to word 13 of test_text set word_14 to word 14 of test_text set word_15 to word 15 of test_text set AppleScript's text item delimiters to "" log word_11 & " " & word_12 & " " & word_13 & " " & word_14 & " " & word_15 The result is: (elev en twelve thir teen) But the result should be an error – it should NOT be using the hyphen as a delimiter. Why is the hyphen being used as a delimiter ? UPDATE: Because I should be using "text item" instead of "word"
0
0
1k
Mar ’23
NSBox – What is difference between BoxType.separator and BoxType.primary
Documentation says: BoxType.primary Specifies the primary box appearance. BoxType.separator Specifies that the box is a separator. Nice, but what does it mean ? What does a "primary" box look like ? How is it different to a "secondary" box ? I have tried both forms (in ASOC) and they look the same. So, is there a difference in how they look ? Thanks.
2
0
1k
Mar ’23
Applescript - Search Folders/Files based on string and display in new FINDER WINDOW
I am trying to compile a script that will search based on a STRING and return all folders/files in a NEW SEARCH FINDER WINDOW. Is this possible? This gives me a list on folders/files set thePath to do shell script "find /Users/donwieland/Desktop/ -name ptw*” /Users/donwieland/Desktop//FMP_MISC/ptw_order.fmp12 /Users/donwieland/Desktop//CLIENT FILES/PTW/PTW_Backup/ptw_data.fmp12 /Users/donwieland/Desktop//CLIENT FILES/PTW/PTW_Backup/ptw_lessons.fmp12 /Users/donwieland/Desktop//CLIENT FILES/PTW/PTW_Backup/ptw contact info.fmp12 /Users/donwieland/Desktop//CLIENT FILES/PTW/PTW_Backup/ptwonlin_sys_2022-02-24.sql /Users/donwieland/Desktop//CLIENT FILES/PTW/PTW_Backup/ptw_orders_test.fmp12 /Users/donwieland/Desktop//mData/PTW_doc/ptw_data_ddr /Users/donwieland/Desktop//mData/PTW_doc/ptw_data_ddr/ptw_data.html /Users/donwieland/Desktop//mData/PTW_doc/ptw_data_ddr/ptw_data_n.html /Users/donwieland/Desktop//PTW_Appts/ptw_lessons_ddr /Users/donwieland/Desktop//PTW_Appts/ptw_lessons_ddr/ptw_lessons_n.html /Users/donwieland/Desktop//PTW_Appts/ptw_lessons_ddr/ptw_lessons.html now I want to open a new FINDER WINDOW and have these items listed. Similar to if a did a manual SEARCH. Thanks in advanced. Don
2
0
1.2k
Mar ’23
Applescript
Hi, I want to write the script which counts folders in catalog, create new catalog with number +1, create subfolder with date and name which I provide in form. tell application "Finder" activate set myCount to 6801 + (count (folders of folder "OZ" of disk "_NEW")) make new folder at folder "OZ" of disk "_NEW" with properties {name:"temp"} tell application "Finder" to open "_NEW:OZ:temp" set name of folder "temp" of folder "OZ" of disk "_NEW" to myCount set myName to text returned of (display dialog "Name:" default answer "Name") set myTime to (do shell script "date +\"%D\"") make new folder at folder "myCount" of folder "OZ" of disk "_NEW" with properties {name:"temp2"} set name of folder "temp2" of folder "myCount" of folder "OZ" of disk "_NEW" to myTime end tell Problem: make new folder at folder „myCount" of folder "OZ" of disk „_NEW" with properties {name:”temp2"} Whene I add aquote it not a varible anymore. Thanks
1
0
1.7k
Mar ’23
How to open Software Update in System Settings on Ventura from applescript?
This no longer works the way it used to back in older versions when System Settings was System Preferences, i.e. set the current pane to pane id "com.apple.preferences.softwareupdate" I had a little applescript saved as an app that would open Preferences to Software Update, and open the App Store and send it the keystroke shortcut for its Updates tab (since App Store is apparently not properly scriptable). Handy to quickly check both, but doesn't work anymore :-(
5
0
2.3k
Mar ’23
Issue with pre-compiling Applescript in Swift 5
I am using information from the post at https://developer.apple.com/forums/thread/98830 Hi, I am using the example from the above forum post in my Swift app and it's working perfectly however pre-compiling the app is causing me an issue. My script is checking if an app existing using Finder and does this before doing other tasks but for some reason. when my app first runs and the script compiles, it is looking for the app and prompting the user to choose it. Any subsequent script calls work as expected.     let script = NSAppleScript(source: """       on lazyPasteRDP()         try           tell application "Finder" to get displayed name of application file id "com.microsoft.rdc.macos"           set appExists to true         on error           set appExists to false         end try         if appExists           tell application "System Events"             set activeApp to name of first application process whose frontmost is true             if "Microsoft Remote Desktop" is in activeApp then               tell application "myApplication"                 activate               end tell               tell application "Microsoft Remote Desktop"                 activate                 delay 0.5                 tell application "System Events" to keystroke "v" using control down               end tell             else               tell application "System Events" to keystroke "v" using command down             end if           end tell         else           tell application "System Events" to keystroke "v" using command down         end if       end lazyPasteRDP       """     )! Is there a way to prevent prompting the user to choose the app during compile time? Again, once the script is compiled, the logic works as expected and doesn't prompt again. The other option would be to only compile the script on a condition but my feeble attempts haven't worked. I tried to post a comment in the original thread but couldn't get enough detail in the 500 character limit
2
0
1k
Mar ’23
Fix iTunes / Music dead tracks with AppleScript
Hi, For a few days, I have more than 5000 dead tracks in my Music library. I'm a developer and I tried to fix the problem like I did before with an AppleScript library but here something strange happened. Indeed, all my dead track are on my external hard drive but the location in Music begins with "file:///Volumes/" so Music can't read the files : The correct path is the same without "file:///Volumes/" : I though it will be easy to fix that but when I try to get the tracks location to trunk it, the value is missing. So how can I fix that ? Thx
1
0
1.5k
Mar ’23
Error in Apple script for saving password-protected PDF
Can anyone please help me find a solution for the error I'm getting? MacOS is Monterrey and this script used to work in Big Sur. It seems it is unable to find splitter group 3 (which would the page style). And the same happens when it tries to find "PDF" splitter and save as PDF. I would appreciate any help/suggestions you can provide. -- Don't change this set FixedPassword to "somePW" --Change the following for each Review accordingly set exam to "2" set session to "5" set VarPassword to "anotherPW" set outpath to "/Users/user/Dropbox/Physics" & " - " & "Current/2023-1-Spring/UF/2." & " " & "Chapter" & " " & "Reviews/" & ¬ "Exam" & " " & exam & " " & "Session" & " " & session & "/E" & exam & "S" & session & ".pdf" set SaveFolder to "/Users/user/Dropbox/Physics" & " - " & "Current/2023-1-Spring/UF/2." & " " & "Chapter" & " " & "Reviews/" & ¬ "Exam" & " " & exam & " " & "Session" & " " & session set FileName to "E" & exam & "S" & session & " " & "(Password" & " - " & VarPassword & ").pdf" --Saving PDF with password protection tell application "Preview" activate open outpath end tell activate application "Preview" tell application "System Events" tell process "Preview" keystroke "p" using command down delay 0.5 tell front window repeat until exists sheet 1 delay 1 end repeat tell sheet 1 tell splitter group 3 click pop up button 3 click menu item "Review 216 by 279 mm" of menu 1 of pop up button 3 end tell tell splitter group 3 click menu button "PDF" repeat until exists menu 1 of menu button "PDF" delay 3 end repeat click menu item "Save as PDF" of menu 1 of menu button "PDF" end tell end tell end tell -- Make sure the save dialog is visible repeat until exists sheet 1 of sheet 1 of front window delay 5 end repeat tell sheet 1 of sheet 1 of front window click button "Security Options..." end tell tell window "PDF Security Options" set selected to true set focused to true (* click the checkbox to on *) -- NOTE: for some reason there is a delay of about 6 seconds here, I do not know why tell checkbox "Require password to open document" click end tell (* add the password and confirm *) keystroke VarPassword keystroke (ASCII character 9) keystroke VarPassword tell its checkbox "Require password to copy text, images and other content" click end tell (* add the password and confirm *) keystroke FixedPassword keystroke (ASCII character 9) keystroke FixedPassword click button "OK" end tell repeat until exists sheet 1 of sheet 1 of front window delay 0.2 end repeat -- Press command+shift+g to show the "Go" drop down sheet keystroke "g" using {command down, shift down} repeat until exists sheet of sheet 1 of sheet 1 of front window delay 0.2 end repeat delay 0.5 keystroke SaveFolder delay 0.5 click button "Go" of sheet of sheet 1 of sheet 1 of front window -- Now that we are in our desired folder, set the file name and save set value of text field 1 of sheet 1 of sheet 1 of front window to FileName click button "Save" of sheet 1 of sheet 1 of front window end tell end tell But it gives the following error:
1
1
1.2k
Mar ’23
AppleScript "Image Events" does no longer get all Metadata
Using a simple script to get the EXIF-information from a photo tell application "Image Events" set theOpenFile to open "/PATH/TO/IMAGE.HEIC" set theTags to name of metadata tags of theOpenFile close theOpenFile return theTags end tell I get for the same image (from an iPhone) following results macOS 13.2 {"format", "hasAlpha", "formatOptions", "typeIdentifier", "dpiHeight", "dpiWidth", "path"} macOS 10.14.6 (Mojave) {"samplesPerPixel", "hasAlpha", "dpiHeight", "dpiWidth", "bitsPerSample", "profile", "formatOptions", "ExifColorSpace", "pixelHeight", "path", "creation", "software", "space", "pixelWidth", "format", "make", "model", "typeIdentifier"} So it is no longer possible to read the image meta data using AppleScript on macOS Ventura, i.e. the creation date.
3
0
1.5k
Mar ’23
Word file to PDF with osascript
Why is this giving a super messed up PDF with no images? What am I doing wrong? use AppleScript version "2.8" use scripting additions use framework "Foundation" use framework "AppKit" -- dimensions of print area: property thePaperSize : {height:479, width:516} property theLeft : 0 property theRight : 0 property theTop : 0 property theBottom : 0 on run argv set course to "course1" set theyear to "2023" set semester to "Spring" set exam to item 1 of argv set session to item 2 of argv set chapters to item 3 of argv if semester="Spring" then set sem_num to "1" else if semester="Summer" then set sem_num to "2" else if semester="Fall" then set sem_num to "3" else return "wrong semester" end if set inpath to "/Users/Dropbox/"& course &" - " & "Current/" & theyear & "-"& sem_num &"-"& semester &"/2." & " " & "Chapter" & " " & "Reviews/" & ¬ "Exam" & " " & exam & " " & "Session" & " " & session & "/"& course &" Exam " & exam & " Session " & session & " (Ch "& chapters &").docx" -- choose Word document file, make URL and build destination path set posixPath to inpath set theURL to current application's |NSURL|'s fileURLWithPath:posixPath set destPath to theURL's |path|()'s stringByDeletingPathExtension()'s stringByAppendingPathExtension:"pdf" -- get doc's contents as styled text set {styledText, theError} to current application's NSAttributedString's alloc()'s initWithURL:theURL options:(missing value) documentAttributes:(missing val$ if styledText = missing value then error (theError's localizedDescription() as text) -- set up printing specs set printInf to current application's NSPrintInfo's sharedPrintInfo()'s |copy|() printInf's setJobDisposition:(current application's NSPrintSaveJob) printInf's dictionary()'s setObject:destPath forKey:(current application's NSPrintSavePath) -- make text view and add text set theView to current application's NSTextView's alloc()'s initWithFrame:{{0, 0}, {(width of thePaperSize) - theLeft - theRight, (height of thePaperSize) - $ theView's textStorage()'s setAttributedString:styledText -- set up and run print operation without showing dialog set theOp to current application's NSPrintOperation's printOperationWithView:theView printInfo:printInf theOp's setShowsPrintPanel:false theOp's setShowsProgressPanel:false theOp's runOperation() end run
2
0
927
Mar ’23
AppleScript to Map Network Drive (Finder > GO > Connect to Server..)
I can successfully map my Windows share (SMB) file on MacOS through Finder > GO > Connect to Server …. I want to automate this process by creating a simple AppleScript (MapDrive.scpt) file, so that anyone can easily run this script to map the drive location easily and quickly. I tried to record the process with the help of Record button on Script Editor, but getting strange script, and also throwing error - apple script error cant get 'connect to server'. Any suggestions or any other method, script, terminal command to automate this issue. Can I create a link to map network drive? How? Thanks
2
0
1.5k
Mar ’23
Text location within a AppleScript List
From the Mac Automation Scripting Guide, listing 21-20 (https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/ManipulateListsofItems.html#//apple_ref/doc/uid/TP40016239-CH48-SW1) is an example handler to find the location of a sting in an AppleScript List: on getPositionOfItemInList(theItem, theList) repeat with a from 1 to count of theList if item a of theList is theItem then return a end repeat return 0 end getPositionOfItemInList If I use this Handler in the following test AppleScript (Note: I have multiple "log" calls to identify various variables and their class. See results): on getPositionOfItemInList(theItem, theList) log (the class of theItem) & "- theItem-" & theItem repeat with position from 1 to count of theList if item position of theList is equal to theItem then return position -- "is" or "is equal to" or "=" are all equivalent end repeat return 0 end getPositionOfItemInList set NAS_Names to {"Time Machine NAS", "Share Drives NAS"} -- Initialise the Disk names set selectedNAS_List to choose from list NAS_Names with prompt "Choose NAS drive/s to wake up" with multiple selections allowed set pass to 0 repeat with selectedNAS in selectedNAS_List set pass to pass + 1 log "Pass # " & pass log (the class of selectedNAS) & "- the class of selectedNAS-" & selectedNAS log getPositionOfItemInList(selectedNAS, NAS_Names) & "- the item position in the list" end repeat Results in the following: tell application "Script Editor" choose from list {"Time Machine NAS", "Share Drives NAS"} with prompt "Choose NAS drive/s to wake up" with multiple selections allowed --> {"Time Machine NAS"} end tell (Pass # 1) (text, - the class of selectedNAS-, Time Machine NAS) (text, - theItem-, Time Machine NAS) (0, - the item position in the list) -- I.E., no match found However: If I change the Handler to: on getPositionOfItemInList(theItem as text, theList) or if item position of theList is equal to theItem as text then return position or if item position of theList contains theItem then return position or if (offset of theItem in (item position of theList)) is equal to 1 then return position Alternatively, if the call to the handler is changed to: getPositionOfItemInList(selectedNAS as text, NAS_Names) or set selectedNAS to selectedNAS as text before the call to the handler Then the Handler works fine and finds the text string in the list, see the example below: on getPositionOfItemInList(theItem, theList) log (the class of theItem) & "- theItem-" & theItem repeat with position from 1 to count of theList if item position of theList is equal to theItem as text then return position end repeat return 0 end getPositionOfItemInList set NAS_Names to {"Time Machine NAS", "Share Drives NAS"} -- Initialise the Disk names set selectedNAS_List to choose from list NAS_Names with prompt "Choose NAS drive/s to wake up" with multiple selections allowed set pass to 0 repeat with selectedNAS in selectedNAS_List --set selectedNAS to selectedNAS as text set pass to pass + 1 log "Pass # " & pass log (the class of selectedNAS) & "- the class of selectedNAS-" & selectedNAS log getPositionOfItemInList(selectedNAS, NAS_Names) & "- the item position in the list" end repeat Results in: tell application "Script Editor" choose from list {"Time Machine NAS", "Share Drives NAS"} with prompt "Choose NAS drive/s to wake up" with multiple selections allowed --> {"Time Machine NAS"} end tell (Pass # 1) (text, - the class of selectedNAS-, Time Machine NAS) (text, - theItem-, Time Machine NAS) (1, - the item position in the list) -- I.E., match found My question is, why is it necessary to coerce what appears to be a text string to text? The result from "choose from list" is a list. However, the result of the "repeat with -- in" appears to be a text string, not a list according to the log output of its class. So why, for this handler to work correctly, does the result from the "repeat with" have to be coerced to text with the "as text"? Is this just a strange quirk of AppleScript? Is the "repeat with -- in" not extracting a text string but something else that is not identified by the "class of" command, hence needing to be coerced? Even though I have this handler working, I would love to know the answer. Thanks in advance.
2
0
851
Mar ’23
A couple of questions about scripting automation on a Mac
I have been writing scripts in AutoIT for windows based systems and now I need to duplicate those scripts for use on Macs (M1 and M2). AutoIT is windows only so that will not work. I haven't written scripts for Macs before. I need to be able to retrieve basic system information, create a simple UI for the script, open apps, manipulate the UI by sending keystrokes and/or mouse clicks, get start and end times for tasks performed (I was able to detect the end of a task on Windows system by checking pixel changes on the screen), and output times and system info to a CSV file. Is Applescript a good tool for this? Should I look into Python or something else? Any recommendations would be helpful.
1
0
584
Mar ’23
AppleScript difference between scpt and app
I have the following Applescript XY.scpt which runs perfect from within the ScriptEditor. But after exporting it to an App (XY.app) it breaks with the message "System Events got an error: XY not allowed assistive access." (-1719)". This is in Ventura 13.3 and the script XY is allowed for Accessibility and Automation in System Settings Security&Privacy. set CR to ASCII character 13 set my0xC9 to ASCII character 201 tell application "Notes" activate set uiScript to "click menu item \"export as pdf" & my0xC9 & "\" of menu 1 of menu bar item \"File\" of menu bar 1 of application process \"Notes\"" run script "tell application \"System Events\" " & CR & uiScript & CR & " end tell" end tell Thanks for your help, ideas and input!
Replies
4
Boosts
0
Views
893
Activity
Apr ’23
Select document name Folder inside subfolder
hello, how can we make a script that can open a folder with the name of a pdf document I choose on the desktop and put this pdf in that folder, and also open a subfolder named “incoming” in this folder and put it in the same pdf folder. sorry for my poor English. The script below does the first stage of the scenario I want, what I want after that is to open another folder named “incoming” in the resulting folder and copy the same first document to this folder named “incoming”, at the end of the job, 2 folders inside each other and the document I selected in the first place. It should be, thank you very much. tell application “Finder” activate set selectedFiles to selection as alias list set containingFolder to container of (item 1 of selectedFiles) --as alias repeat with i from 1 to count of selectedFiles set foldersRef to (a reference to folders of containingFolder) set foldersRefItems to name of (contents of foldersRef) set thisItem to item i of selectedFiles set fileName to (text items 1 thru -5) of (name of thisItem as text) as string if fileName is not in foldersRefItems then move thisItem to (make new folder at containingFolder ¬ with properties {name:fileName}) else move thisItem to folder fileName of containingFolder end if end repeat Summary Select Desktop/demo.pdf ———start script Final
Replies
0
Boosts
0
Views
498
Activity
Mar ’23
How to use YOLOv3 from applescript
Hello. I would like to compile the YOLOv3.mlmodel for object detection as a framework and call it from applescript to use it, but I do not know how. The flow I am imagining is as follows Import "YOLOv3.mlmodel" on xcode and create a framework. Load the created framework with applescript's use statement and execute it. Please let me know if you know anything about this.
Replies
1
Boosts
0
Views
855
Activity
Mar ’23
AppleScript – "text item delimiters" uses non-specified delimiters - FIXED
SOLVED I want to parse some plain text and pull out the 11th and 13th words. I can't get it to work because "text item delimiters" sometimes treats additional characters as delimiters. set test_text to "one two three four five six seven eight nine ten elev-en twelve thir-teen" set AppleScript's text item delimiters to "" set AppleScript's text item delimiters to {" "} set word_11 to word 11 of test_text set word_12 to word 12 of test_text set word_13 to word 13 of test_text set word_14 to word 14 of test_text set word_15 to word 15 of test_text set AppleScript's text item delimiters to "" log word_11 & " " & word_12 & " " & word_13 & " " & word_14 & " " & word_15 The result is: (elev en twelve thir teen) But the result should be an error – it should NOT be using the hyphen as a delimiter. Why is the hyphen being used as a delimiter ? UPDATE: Because I should be using "text item" instead of "word"
Replies
0
Boosts
0
Views
1k
Activity
Mar ’23
NSBox – What is difference between BoxType.separator and BoxType.primary
Documentation says: BoxType.primary Specifies the primary box appearance. BoxType.separator Specifies that the box is a separator. Nice, but what does it mean ? What does a "primary" box look like ? How is it different to a "secondary" box ? I have tried both forms (in ASOC) and they look the same. So, is there a difference in how they look ? Thanks.
Replies
2
Boosts
0
Views
1k
Activity
Mar ’23
Applescript - Search Folders/Files based on string and display in new FINDER WINDOW
I am trying to compile a script that will search based on a STRING and return all folders/files in a NEW SEARCH FINDER WINDOW. Is this possible? This gives me a list on folders/files set thePath to do shell script "find /Users/donwieland/Desktop/ -name ptw*” /Users/donwieland/Desktop//FMP_MISC/ptw_order.fmp12 /Users/donwieland/Desktop//CLIENT FILES/PTW/PTW_Backup/ptw_data.fmp12 /Users/donwieland/Desktop//CLIENT FILES/PTW/PTW_Backup/ptw_lessons.fmp12 /Users/donwieland/Desktop//CLIENT FILES/PTW/PTW_Backup/ptw contact info.fmp12 /Users/donwieland/Desktop//CLIENT FILES/PTW/PTW_Backup/ptwonlin_sys_2022-02-24.sql /Users/donwieland/Desktop//CLIENT FILES/PTW/PTW_Backup/ptw_orders_test.fmp12 /Users/donwieland/Desktop//mData/PTW_doc/ptw_data_ddr /Users/donwieland/Desktop//mData/PTW_doc/ptw_data_ddr/ptw_data.html /Users/donwieland/Desktop//mData/PTW_doc/ptw_data_ddr/ptw_data_n.html /Users/donwieland/Desktop//PTW_Appts/ptw_lessons_ddr /Users/donwieland/Desktop//PTW_Appts/ptw_lessons_ddr/ptw_lessons_n.html /Users/donwieland/Desktop//PTW_Appts/ptw_lessons_ddr/ptw_lessons.html now I want to open a new FINDER WINDOW and have these items listed. Similar to if a did a manual SEARCH. Thanks in advanced. Don
Replies
2
Boosts
0
Views
1.2k
Activity
Mar ’23
Applescript
Hi, I want to write the script which counts folders in catalog, create new catalog with number +1, create subfolder with date and name which I provide in form. tell application "Finder" activate set myCount to 6801 + (count (folders of folder "OZ" of disk "_NEW")) make new folder at folder "OZ" of disk "_NEW" with properties {name:"temp"} tell application "Finder" to open "_NEW:OZ:temp" set name of folder "temp" of folder "OZ" of disk "_NEW" to myCount set myName to text returned of (display dialog "Name:" default answer "Name") set myTime to (do shell script "date +\"%D\"") make new folder at folder "myCount" of folder "OZ" of disk "_NEW" with properties {name:"temp2"} set name of folder "temp2" of folder "myCount" of folder "OZ" of disk "_NEW" to myTime end tell Problem: make new folder at folder „myCount" of folder "OZ" of disk „_NEW" with properties {name:”temp2"} Whene I add aquote it not a varible anymore. Thanks
Replies
1
Boosts
0
Views
1.7k
Activity
Mar ’23
How to open Software Update in System Settings on Ventura from applescript?
This no longer works the way it used to back in older versions when System Settings was System Preferences, i.e. set the current pane to pane id "com.apple.preferences.softwareupdate" I had a little applescript saved as an app that would open Preferences to Software Update, and open the App Store and send it the keystroke shortcut for its Updates tab (since App Store is apparently not properly scriptable). Handy to quickly check both, but doesn't work anymore :-(
Replies
5
Boosts
0
Views
2.3k
Activity
Mar ’23
Issue with pre-compiling Applescript in Swift 5
I am using information from the post at https://developer.apple.com/forums/thread/98830 Hi, I am using the example from the above forum post in my Swift app and it's working perfectly however pre-compiling the app is causing me an issue. My script is checking if an app existing using Finder and does this before doing other tasks but for some reason. when my app first runs and the script compiles, it is looking for the app and prompting the user to choose it. Any subsequent script calls work as expected.     let script = NSAppleScript(source: """       on lazyPasteRDP()         try           tell application "Finder" to get displayed name of application file id "com.microsoft.rdc.macos"           set appExists to true         on error           set appExists to false         end try         if appExists           tell application "System Events"             set activeApp to name of first application process whose frontmost is true             if "Microsoft Remote Desktop" is in activeApp then               tell application "myApplication"                 activate               end tell               tell application "Microsoft Remote Desktop"                 activate                 delay 0.5                 tell application "System Events" to keystroke "v" using control down               end tell             else               tell application "System Events" to keystroke "v" using command down             end if           end tell         else           tell application "System Events" to keystroke "v" using command down         end if       end lazyPasteRDP       """     )! Is there a way to prevent prompting the user to choose the app during compile time? Again, once the script is compiled, the logic works as expected and doesn't prompt again. The other option would be to only compile the script on a condition but my feeble attempts haven't worked. I tried to post a comment in the original thread but couldn't get enough detail in the 500 character limit
Replies
2
Boosts
0
Views
1k
Activity
Mar ’23
Fix iTunes / Music dead tracks with AppleScript
Hi, For a few days, I have more than 5000 dead tracks in my Music library. I'm a developer and I tried to fix the problem like I did before with an AppleScript library but here something strange happened. Indeed, all my dead track are on my external hard drive but the location in Music begins with "file:///Volumes/" so Music can't read the files : The correct path is the same without "file:///Volumes/" : I though it will be easy to fix that but when I try to get the tracks location to trunk it, the value is missing. So how can I fix that ? Thx
Replies
1
Boosts
0
Views
1.5k
Activity
Mar ’23
Error in Apple script for saving password-protected PDF
Can anyone please help me find a solution for the error I'm getting? MacOS is Monterrey and this script used to work in Big Sur. It seems it is unable to find splitter group 3 (which would the page style). And the same happens when it tries to find "PDF" splitter and save as PDF. I would appreciate any help/suggestions you can provide. -- Don't change this set FixedPassword to "somePW" --Change the following for each Review accordingly set exam to "2" set session to "5" set VarPassword to "anotherPW" set outpath to "/Users/user/Dropbox/Physics" & " - " & "Current/2023-1-Spring/UF/2." & " " & "Chapter" & " " & "Reviews/" & ¬ "Exam" & " " & exam & " " & "Session" & " " & session & "/E" & exam & "S" & session & ".pdf" set SaveFolder to "/Users/user/Dropbox/Physics" & " - " & "Current/2023-1-Spring/UF/2." & " " & "Chapter" & " " & "Reviews/" & ¬ "Exam" & " " & exam & " " & "Session" & " " & session set FileName to "E" & exam & "S" & session & " " & "(Password" & " - " & VarPassword & ").pdf" --Saving PDF with password protection tell application "Preview" activate open outpath end tell activate application "Preview" tell application "System Events" tell process "Preview" keystroke "p" using command down delay 0.5 tell front window repeat until exists sheet 1 delay 1 end repeat tell sheet 1 tell splitter group 3 click pop up button 3 click menu item "Review 216 by 279 mm" of menu 1 of pop up button 3 end tell tell splitter group 3 click menu button "PDF" repeat until exists menu 1 of menu button "PDF" delay 3 end repeat click menu item "Save as PDF" of menu 1 of menu button "PDF" end tell end tell end tell -- Make sure the save dialog is visible repeat until exists sheet 1 of sheet 1 of front window delay 5 end repeat tell sheet 1 of sheet 1 of front window click button "Security Options..." end tell tell window "PDF Security Options" set selected to true set focused to true (* click the checkbox to on *) -- NOTE: for some reason there is a delay of about 6 seconds here, I do not know why tell checkbox "Require password to open document" click end tell (* add the password and confirm *) keystroke VarPassword keystroke (ASCII character 9) keystroke VarPassword tell its checkbox "Require password to copy text, images and other content" click end tell (* add the password and confirm *) keystroke FixedPassword keystroke (ASCII character 9) keystroke FixedPassword click button "OK" end tell repeat until exists sheet 1 of sheet 1 of front window delay 0.2 end repeat -- Press command+shift+g to show the "Go" drop down sheet keystroke "g" using {command down, shift down} repeat until exists sheet of sheet 1 of sheet 1 of front window delay 0.2 end repeat delay 0.5 keystroke SaveFolder delay 0.5 click button "Go" of sheet of sheet 1 of sheet 1 of front window -- Now that we are in our desired folder, set the file name and save set value of text field 1 of sheet 1 of sheet 1 of front window to FileName click button "Save" of sheet 1 of sheet 1 of front window end tell end tell But it gives the following error:
Replies
1
Boosts
1
Views
1.2k
Activity
Mar ’23
AppleScript "Image Events" does no longer get all Metadata
Using a simple script to get the EXIF-information from a photo tell application "Image Events" set theOpenFile to open "/PATH/TO/IMAGE.HEIC" set theTags to name of metadata tags of theOpenFile close theOpenFile return theTags end tell I get for the same image (from an iPhone) following results macOS 13.2 {"format", "hasAlpha", "formatOptions", "typeIdentifier", "dpiHeight", "dpiWidth", "path"} macOS 10.14.6 (Mojave) {"samplesPerPixel", "hasAlpha", "dpiHeight", "dpiWidth", "bitsPerSample", "profile", "formatOptions", "ExifColorSpace", "pixelHeight", "path", "creation", "software", "space", "pixelWidth", "format", "make", "model", "typeIdentifier"} So it is no longer possible to read the image meta data using AppleScript on macOS Ventura, i.e. the creation date.
Replies
3
Boosts
0
Views
1.5k
Activity
Mar ’23
Where to find some commonly used AppleScript examples to automate basic MacOS tasks?
Where to find some commonly used AppleScript examples to automate basic MacOS tasks? Any link, website, tutorials, guides, etc. Any other well know AppleScript forum than this one. Thanks!
Replies
2
Boosts
0
Views
1.4k
Activity
Mar ’23
Word file to PDF with osascript
Why is this giving a super messed up PDF with no images? What am I doing wrong? use AppleScript version "2.8" use scripting additions use framework "Foundation" use framework "AppKit" -- dimensions of print area: property thePaperSize : {height:479, width:516} property theLeft : 0 property theRight : 0 property theTop : 0 property theBottom : 0 on run argv set course to "course1" set theyear to "2023" set semester to "Spring" set exam to item 1 of argv set session to item 2 of argv set chapters to item 3 of argv if semester="Spring" then set sem_num to "1" else if semester="Summer" then set sem_num to "2" else if semester="Fall" then set sem_num to "3" else return "wrong semester" end if set inpath to "/Users/Dropbox/"& course &" - " & "Current/" & theyear & "-"& sem_num &"-"& semester &"/2." & " " & "Chapter" & " " & "Reviews/" & ¬ "Exam" & " " & exam & " " & "Session" & " " & session & "/"& course &" Exam " & exam & " Session " & session & " (Ch "& chapters &").docx" -- choose Word document file, make URL and build destination path set posixPath to inpath set theURL to current application's |NSURL|'s fileURLWithPath:posixPath set destPath to theURL's |path|()'s stringByDeletingPathExtension()'s stringByAppendingPathExtension:"pdf" -- get doc's contents as styled text set {styledText, theError} to current application's NSAttributedString's alloc()'s initWithURL:theURL options:(missing value) documentAttributes:(missing val$ if styledText = missing value then error (theError's localizedDescription() as text) -- set up printing specs set printInf to current application's NSPrintInfo's sharedPrintInfo()'s |copy|() printInf's setJobDisposition:(current application's NSPrintSaveJob) printInf's dictionary()'s setObject:destPath forKey:(current application's NSPrintSavePath) -- make text view and add text set theView to current application's NSTextView's alloc()'s initWithFrame:{{0, 0}, {(width of thePaperSize) - theLeft - theRight, (height of thePaperSize) - $ theView's textStorage()'s setAttributedString:styledText -- set up and run print operation without showing dialog set theOp to current application's NSPrintOperation's printOperationWithView:theView printInfo:printInf theOp's setShowsPrintPanel:false theOp's setShowsProgressPanel:false theOp's runOperation() end run
Replies
2
Boosts
0
Views
927
Activity
Mar ’23
AppleScript to Map Network Drive (Finder > GO > Connect to Server..)
I can successfully map my Windows share (SMB) file on MacOS through Finder > GO > Connect to Server …. I want to automate this process by creating a simple AppleScript (MapDrive.scpt) file, so that anyone can easily run this script to map the drive location easily and quickly. I tried to record the process with the help of Record button on Script Editor, but getting strange script, and also throwing error - apple script error cant get 'connect to server'. Any suggestions or any other method, script, terminal command to automate this issue. Can I create a link to map network drive? How? Thanks
Replies
2
Boosts
0
Views
1.5k
Activity
Mar ’23
javascript in AppleScript
Good evening everyone. I can't run a line of JavaScript in AppleScript. Is that normal? It's normal? Thank you in advance.
Replies
2
Boosts
0
Views
3.6k
Activity
Mar ’23
Text location within a AppleScript List
From the Mac Automation Scripting Guide, listing 21-20 (https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/ManipulateListsofItems.html#//apple_ref/doc/uid/TP40016239-CH48-SW1) is an example handler to find the location of a sting in an AppleScript List: on getPositionOfItemInList(theItem, theList) repeat with a from 1 to count of theList if item a of theList is theItem then return a end repeat return 0 end getPositionOfItemInList If I use this Handler in the following test AppleScript (Note: I have multiple "log" calls to identify various variables and their class. See results): on getPositionOfItemInList(theItem, theList) log (the class of theItem) & "- theItem-" & theItem repeat with position from 1 to count of theList if item position of theList is equal to theItem then return position -- "is" or "is equal to" or "=" are all equivalent end repeat return 0 end getPositionOfItemInList set NAS_Names to {"Time Machine NAS", "Share Drives NAS"} -- Initialise the Disk names set selectedNAS_List to choose from list NAS_Names with prompt "Choose NAS drive/s to wake up" with multiple selections allowed set pass to 0 repeat with selectedNAS in selectedNAS_List set pass to pass + 1 log "Pass # " & pass log (the class of selectedNAS) & "- the class of selectedNAS-" & selectedNAS log getPositionOfItemInList(selectedNAS, NAS_Names) & "- the item position in the list" end repeat Results in the following: tell application "Script Editor" choose from list {"Time Machine NAS", "Share Drives NAS"} with prompt "Choose NAS drive/s to wake up" with multiple selections allowed --> {"Time Machine NAS"} end tell (Pass # 1) (text, - the class of selectedNAS-, Time Machine NAS) (text, - theItem-, Time Machine NAS) (0, - the item position in the list) -- I.E., no match found However: If I change the Handler to: on getPositionOfItemInList(theItem as text, theList) or if item position of theList is equal to theItem as text then return position or if item position of theList contains theItem then return position or if (offset of theItem in (item position of theList)) is equal to 1 then return position Alternatively, if the call to the handler is changed to: getPositionOfItemInList(selectedNAS as text, NAS_Names) or set selectedNAS to selectedNAS as text before the call to the handler Then the Handler works fine and finds the text string in the list, see the example below: on getPositionOfItemInList(theItem, theList) log (the class of theItem) & "- theItem-" & theItem repeat with position from 1 to count of theList if item position of theList is equal to theItem as text then return position end repeat return 0 end getPositionOfItemInList set NAS_Names to {"Time Machine NAS", "Share Drives NAS"} -- Initialise the Disk names set selectedNAS_List to choose from list NAS_Names with prompt "Choose NAS drive/s to wake up" with multiple selections allowed set pass to 0 repeat with selectedNAS in selectedNAS_List --set selectedNAS to selectedNAS as text set pass to pass + 1 log "Pass # " & pass log (the class of selectedNAS) & "- the class of selectedNAS-" & selectedNAS log getPositionOfItemInList(selectedNAS, NAS_Names) & "- the item position in the list" end repeat Results in: tell application "Script Editor" choose from list {"Time Machine NAS", "Share Drives NAS"} with prompt "Choose NAS drive/s to wake up" with multiple selections allowed --> {"Time Machine NAS"} end tell (Pass # 1) (text, - the class of selectedNAS-, Time Machine NAS) (text, - theItem-, Time Machine NAS) (1, - the item position in the list) -- I.E., match found My question is, why is it necessary to coerce what appears to be a text string to text? The result from "choose from list" is a list. However, the result of the "repeat with -- in" appears to be a text string, not a list according to the log output of its class. So why, for this handler to work correctly, does the result from the "repeat with" have to be coerced to text with the "as text"? Is this just a strange quirk of AppleScript? Is the "repeat with -- in" not extracting a text string but something else that is not identified by the "class of" command, hence needing to be coerced? Even though I have this handler working, I would love to know the answer. Thanks in advance.
Replies
2
Boosts
0
Views
851
Activity
Mar ’23
AppleScript code to run Firefox in incognito mode with proxy IP xx.xx.xx.xx Port xxxx?
How can I write an AppleScript code to run Firefox in incognito mode with proxy IP xx.xx.xx.xx Port xxxx configured?
Replies
1
Boosts
0
Views
995
Activity
Mar ’23
A couple of questions about scripting automation on a Mac
I have been writing scripts in AutoIT for windows based systems and now I need to duplicate those scripts for use on Macs (M1 and M2). AutoIT is windows only so that will not work. I haven't written scripts for Macs before. I need to be able to retrieve basic system information, create a simple UI for the script, open apps, manipulate the UI by sending keystrokes and/or mouse clicks, get start and end times for tasks performed (I was able to detect the end of a task on Windows system by checking pixel changes on the screen), and output times and system info to a CSV file. Is Applescript a good tool for this? Should I look into Python or something else? Any recommendations would be helpful.
Replies
1
Boosts
0
Views
584
Activity
Mar ’23
Can it auto choose don't import apply to all duplicates in Apple Script
I was trying to write a script that can automatically import new photos in to the Photoslibrary, in AppleScript, there are only bool value to determine whether check duplicates, is there a way to do like " check and always do not import duplicate items "
Replies
1
Boosts
0
Views
873
Activity
Mar ’23