error with automator applescript “do shell script” call (file not found) yet command line with same command works

I have a simple automator app that runs a simple script. It uses ssh to open a file on the local machine, MachineA, with an app on the remote machine, MachineB, and logs the ssh call.

on run {input, parameters}     repeat with fn in input         set fn to POSIX path of fn         set fn to "/Volumes/MachineA" & fn         set fn to "\"/usr/bin/open -a /Applications/Preview.app " & fn & "\""         set cmd to "ssh -x MachineB.local " & quoted form of fn         do shell script "echo " & cmd & " >> ~/cmd.log"         do shell script cmd     end repeat end run 

The log output is:

ssh -x MachineB.local "/usr/bin/open -a /Applications/Preview.app /Volumes/MachineA/Users/<USER>/Documents/<FOLDER>/<FILE>.pdf" 

When I use the app to open a file (drag & drop), an error is thrown.

error message

However, if I copy the output in the log file to the command line, success, the file is opened on the remote machine. Why the difference?

AppleScript to clean spam in Messages

I get a lot of spam in my iMessage, such gamble, sex etc.

  • On my iPhone, it can be filtered into a separate column.

  • But on my Mac, there is no way to filter messages from unknown senders, which is annoying.

iPhone

Mac

Question

Is there a way to write an AppleScript to clean spam messages that contain specific words? I can trigger it at a certain interval to clean up spam messages.

AppleScript for Excel to select/copy all cells?

Applescript can tell Excel to select a specific range of cells, e.g.

select (range "A1:B20")

and you can copy cells:

copy (range "A1:B20")

However, how can you tell Excel to select all the cells in a worksheet, or to copy all the cells in a worksheet? It seems to require a specific range. However, of course, when you are working with Excel directly you can just press cmd+A to select all.

Refactoring Inelegant AppleScript to Use Recursion

I’ve written an AppleScript to iterate through an app’s menu choices, doing something with each item (e.g., get its keyboard shortcut). It works, though (being AppleScript) it’s very slow, but I’m unsatisfied with it.

As you can see from the skeleton below, I’ve used a brute force nesting of repeat loops to work down through the menu tree. It gets particularly ugly when the skeleton is fleshed out to do actual work, requiring repetition of instructions so brief that putting them into their own handlers doesn’t really help.

It seems like a recursive algorithm would be a more elegant solution, but I’ve been unable to implement one. I’ve foundered on AppleScript’s lack of dynamic variable assignment.

Is there a more elegant solution?

-- Iterates through an app's menus, performing an action on each item  --list of apps to process set theApps to {"Stickies"}  repeat with thisProc in theApps      --wake up     launch application thisProc      --process this process     tell application "System Events" to tell process thisProc          --iterate through submenus, ignoring anything beyond three levels          --there are always menu bar items         repeat with levelOne in menu bar items 2 through -1 of menu bar 1             Get_Something of me from levelOne             --there are always level 1 menu items contained in a menu 1             repeat with levelTwo in (menu items of menu 1) of levelOne                 Get_Something of me from levelTwo                 --fail silently if there's no level 3                 try                     repeat with levelThree in (menu items of menu 1)                         Get_Something of me from levelThree given indent:3                         --fail silently if there's no level 4                         try                             repeat with levelFour in (menu items of menu 1) of levelThree                                 Get_Something of me from levelFour                             end repeat                         end try                     end repeat                 end try             end repeat         end repeat     end tell end repeat  to Get_Something from thisItem      tell application "System Events" to set theName to title of thisItem      --ignore menu separators     if theName is not missing value and theName is not "" then         say theName     end if  end Get_Something 

Adding hyperlink within message content of new email using AppleScript

I’ve been searching the internet but am having trouble finding a way to attach a hyperlink to a new email using applescript.

The most helpful link I’ve found is from 2008, and I believe the poster was eventually able to add a hyperlink, but only within a mail signature.

https://discussions.apple.com/thread/1687240

I am already using another mail signature and I’m wondering if there is some other way to do this since it’s been 10 years since the original post.

This is an example of my code:


property thesender : “Belinda “

tell application “Microsoft Excel” set lasty to first row index of (get end (last cell of column 1 of sheet 1) direction toward the top) end tell

repeat with i from 2 to lasty

tell application "Microsoft Excel"      set pername to value of column 1 of row i of sheet 1 of active workbook as text      set peremail to value of column 2 of row i of sheet 1 of active workbook as text   end tell   tell application "Mail"      set theAttachmentFile to "Macintosh HD:Users:abc:Desktop:Photos:abc.jpg"      set signatory to "CXO"      set newemail to make new outgoing message with properties {content:"Hi" & space & pername & "," & return & return & "I hope all is well.  My name is Belinda with Company X. We recently published a peer-based Technologies Survey that I thought you would find valuable & wanted to share." & return & return & return & return & "Download your copy of the survey here: Technologies Survey Powered by Company X. 

Please reach out with any questions or if you’d like to learn how our AI-based platform is helping your peers optimize spend.

I look forward to connecting.

Thanks, Belinda”, visible:true, subject:”ABC Survey Results for” & space & pername, message signature:signature signatory}

    tell content of newemail         make new attachment with properties {file name:theAttachmentFile as alias} at after sixth paragraph     end tell      set sender of newemail to thesender      tell newemail          make new to recipient at end of to recipients with properties {name:pername, address:peremail}      end tell  end tell 

end repeat


‘I need the hyperlink to sit within the message content where it says “Download your copy of the survey here.”

Any help would be greatly appreciated!

Make AppleScript turn a variable into the items between two specified items

set theList to {"1", "", "", "apple", "acda", "", "3454", "ImportantStuff", "important1", "important2", "important3", "NotImportantStuff", "2", "", "efrg"} set theImportant to items between "ImportantStuff" and "NonImportantStuff" of theList 

How do I make it so AppleScript takes the items in between “ImportantStuff” and “NonImportantStuff” and assign a variable to those items. the variable “theList” is a substitute, the amount of items that are important (between the two specified items) is indefinite–along with the amount of items before and after the specified items.