hope someone can tell me what I am doing wrong. I am an applescript newby, with help from other posts was able to use automator, applescript & keyboard shortcut to move selected messages to an outlook folder. Worked great. I transferred to another mac, works fine there. Then intermittently I get an error message on both macs:
The action "Run Applescript" encountered an error: "No messages selected. Select at least one message."1
I initially thought it was related to when I last opened up Outlook as it seemed to fix itself after a few minutes. Then problem comes back, no rhyme or reason I can perceive. Yes, I do in fact select a message first.
I made two copies of script, differences are folder names. Two different hotkeys attached, option+B for one folder option+P for another. Same error if I use hotkey or go to outlook/services then select the script
Any clue what I am doing wrong? thanks in advance for any insight!
Outlook for mac / O365 v: 16.62 (22061100)
osx big sur v: 11.6 (20G165)
here is script:
on run {input, parameters}
tell application "Microsoft Outlook"
activate
set msgSet to current messages
if msgSet = {} then
error "No messages selected. Select at least one message."
error -128
end if
set theMsg to item 1 of msgSet
set theAccount to account of theMsg
set archiveFolder to folder "Broker Correspondence" of theAccount
repeat with aMessage in msgSet
move aMessage to archiveFolder
end repeat
end tell
return input
end run
Related
I am trying to move from using Evernote to apple note.
One function that I am missing is from the print menu on a mac to be able to save the PDF to a new note.
I figured that I can create a print_plugin from Automator. I am trying to have an apple script handling the creation of a new note. Googling and using my limited knowledge of apple script I figured that I need to do something like
property accountName : "iCloud"
on run {input, parameters}
tell application "Preview"
open input
end tell
tell application "Notes"
activate
set theFolder to choose from list ((name of folders of account accountName) as list)
if theFolder is not false then
set newNote to make new note in folder (item 1 of theFolder) of account accountName
if input is not {} then
tell newNote
make new attachment with input
show
end tell
end if
end if
end tell
end run
The preview part of the code is to see if the pdf is passed correctly. Preview can indeed open the pdf correctly.
When I run the script I get the following error
The action “Run AppleScript” encountered an error: “Notes got an error: Can’t make show id "x-coredata://726D28C7-1847-43DA-9A8D-A9A1B379DF6F/ICNote/p6780" into type specifier.”
Notes got an error: Can’t make show id "x-coredata://726D28C7-1847-43DA-9A8D-A9A1B379DF6F/ICNote/p6780" into type specifier
If I remove the line
make new attachment with input
the script runs without error (but clearly no attachment is created).
Does anyone have a solution?
Best,
E
Ok, after a lot of meddling I found this sort of solution:
property accountName : "iCloud"
on run {input, parameters}
tell application "Notes"
open input
end tell
end run
When saved as a print plugin, it creates a new note with the title of the webpage and the pdf attached. It creates it in the "Notes" folder, which works fine for me.
Best,
E
trying to reproduce right-click context menu on my Mac.
I found such an article:
https://beebom.com/how-right-click-using-keyboard-mac/
I did accordingly but when I click my keyboard shortcut I get Finder menu not a currently selected file/folder menu.
This is an apple script used,
on run {input, parameters}
tell application "System Events" to set frontApp to name of first process whose frontmost is true
tell application "System Events"
tell application process frontApp
set _selection to value of attribute "AXFocusedUIElement"
tell _selection to perform action "AXShowMenu"
end tell
end tell
return input
end run
Spent hours trying to get this basic and obvious to every Windows user functionality to work, lost of time and very frustrating!
I think code is correct, maybe there is something specific on my computer that stops it from working as expected?
Please help :-)
Not sure i understood what is actually not working for you, but i had problem to reproduce the same script, once i wrote it in Automator.app i tried to press "play" button to see if the script was working and it was telling me something like "syntax error, can't get attribute AXFocusedUIElement of application process Automator" (from memory, not sure it's exactly what was written)
and struggled for a while as well untill i realised there was a pop window that i didn't see, saying me that "automator wants permission to control this computer using accessibility features (this thing in the system preference, security and privacy, privacy, accessibility), so i opened, there was a list of apps allowed to control my computer, i ticked Automator.app and after that it worked
Then every app that i was trying to do a right click was showing me the same pop up and i had to do the same for each one (safari, finder etc...)
And then it worked
Hope might help you!
Encountered same issue.
Allow 'Finder' to control computer at System Preferences>Security & Privacy>Privacy>Accessibility.
Worked for me
I recently started AppleScript and wanted to slowly getting into scripting and hoping someone can help me with a block I have ran into. Tried a few things and moving pieces around and changing identifiers but don't know what I should be looking for to change. Hoping someone can help me out and explain my flaws.
Background Story: Trying to test a script to back up of a user account home folder to an external drive.
What I have first: drive verification to make sure there is a drive plugged into the computer. Followed by setting source and destination. Then tried compiling an if then statement to single out 2 folders I don't want to be copied over (only focusing on the user folder, but unsure if that is correct and will need that looked at too). I get my error at the duplicate command: "Finder got an error: An item with the same name already exist in this location." However, there is nothing the external so I have no clue what else to do. Any advice would be helpful.
This is the code I have to start with:
tell application "System Events" to set diskNames to name of every disk
if "Untitled" is in the diskNames then
display dialog "Disk is mounted" buttons {"OK"} default button 1 with icon 1
else
display dialog "No disk found" buttons {"OK"} default button 1 with icon 1
end if
tell application "Finder"
set source_folder to "Macintosh HD:Users:"
set tar_disk to "Untitled:"
if source_folder is not {"administrator", "Shared"} then
with timeout of 3600 seconds -- 2 hours
duplicate source_folder to tar_disk
end timeout
else
display dialog "No folder detected" buttons {"OK"} default button 1 with icon 1
end if
end tell
You are able to copy only your own home folder with the Finder, you don't have permissions to copy the home folders of other users (except Shared).
Basically it's good habit to add Finder specifiers to literal strings representing files, folders and disks for example
set tar_disk to disk "Untitled"
Since there is a home property pointing to the current home folder you can write
tell application "Finder"
set tar_disk to disk "Untitled"
with timeout of 3600 seconds -- 2 hours
duplicate home to tar_disk
end timeout
end tell
There is an important caveat: The Finder copies only the visible files and folders. If AppleShowAllFiles is set to false all files starting with a dot are ignored. To copy the entire home folder something like the shell rsync command is the better choice – also for speed reasons.
I am developing an automated test for several Mac OSX apps with applescript. The app should do the following.
1.) Display dialog shows up, where the user can type in 1 or more app names he want to be tested for example (1.test.app, 2.autotest.app,....)
2.)depending on how many apps names he has typed in, the apps should start and close consecutively to check if they are working.
So for example if the user type in apptest1.app, apptest2.app, apptest3.app -> the first app starting should be apptest1.app and then close it, the next app should be apptest2.app start and close and so on.
thank you very much.
lg,
San
This should do the trick
tell application "Finder"
set thePath to path to applications folder
set theApps to get name of every file of thePath
set apps_to_test to choose from list (theApps) with multiple selections allowed
end tell
repeat with the_app in apps_to_test
tell application the_app
activate
quit saving no
end tell
end repeat
Good morning,
I am trying to write an AppleScript that I can run that will send all the files on my desktop to Evernote, and then delete the files. My code to date is:
on run {input}
tell application "Finder"
select every file of desktop
end tell
tell application "Evernote"
repeat with SelectedFile in input
try
create note from file SelectedFile notebook "Auto Import"
end try
end repeat
end tell
tell application "Finder"
delete every file of desktop
end tell
end run
If I run this then the first and last 'tell' work fine (ie. the script highlights then deletes all the files on the desktop), but the middle 'tell' doesn't do anything.
However, if I manually highlight all the files on the desktop and then run just the middle 'tell' then it imports fine - each item into a separate note as intended.
As you can tell, I am new to AppleScript - I suspect I need to put the selected files in an array of some sort, but can't figure it out. Help!
Many thanks
Rich
Your code fails because there is no relation between your input variable and the selection of files via Finder – which means that your list is empty, and Evernote is not processing anything at all. You have obfuscated the problem by wrapping the Evernote import command in a try block without any error processing, which means all errors just go unnoticed (to avoid this kind of problem, it is good practice to always log the error message in an on error clause, if nothing else).
Also, you don’t actually need to select files on the Desktop via AppleScript to process them. The following code will grab all visible files (excluding pseudo-files like packages / apps):
tell application "System Events"
set desktopFiles to every disk item of (desktop folder of user domain) whose visible is true and class is file
end tell
Pass the list you retrieved that way to Evernote for processing:
repeat with aFile in desktopFiles as list
try
tell application "Evernote" to create note from file (aFile as alias) notebook "Auto Import"
tell application "System Events" to delete aFile
on error errorMessage
log errorMessage
end try
end repeat
and you are good to go.
Note that by judiciously placing the deletion command (right after the import command, inside the try block, inside the loop over all files), you make sure it is only called if Evernote does not error on import while avoiding having to iterate over the files several times.
A final note: you don’t have to use the block syntax for tell statements if there is only one command to execute – using tell <target> to <command> is easier and will keep you out of nested context hell.
Thanks #adayzone for corrections on list handling and alias coercion
Try
tell application "System Events" to set xxx to get every file of (desktop folder of user domain) whose visible is true
repeat with i from 1 to count of xxx
set SelectedFile to item i of xxx as alias
try
tell application "Evernote" to create note from file SelectedFile notebook "Auto Import"
tell application "Finder" to delete SelectedFile
end try
end repeat
Thanks #fanaugen