Get network address of a file in AppleScript - applescript

We are a network of Mac computers. I would like to send email addresses to colleagues with links to files on network locations. I made the following AppleScript:
tell application "Finder"
set uuu to URL of the first item of (get the selection)
set the clipboard to uuu
end tell
which puts the URL of the currently selected file into the clipboard, which can then be pasted into the message (using the Add Link menu item), providing, for example:
file://localhost/Volumes/Commerciale/Clienti/
Unfortunately these links do not work. If I select Go To Folder from the menu item, I can get to the folder using an afp:// type URL.
Is there any way to get this via AppleScript like I do with URL above?

I have solved with this script:
on urlToPOSIXPath(theURL)
return do shell script "python -c \"import urllib, urlparse, sys; print urllib.unquote(urlparse.urlparse(sys.argv[1])[2])\" " & quoted form of theURL
end urlToPOSIXPath
tell application "Finder"
set uuu to URL of the first item of (get the selection)
set pp to my urlToPOSIXPath(uuu)
set the clipboard to "file://" & pp
end tell

Are the volumes already mounted on the email recipients' Mac? Netlink makes a URL that is clickable in Mail. I don't have an AFP share here to test this:
tell application "Finder" to set netlink to URL of (get selection as alias)

Not "automagically" as far as I know. The URL and POSIX path properties only returns the shared directory and not the volume itself. If you use the URL given to you by Applescript, only Applescript can still resolve it. (I get the impression the OS or Applescript is just iterating down the mounted volumes finding the file) You'll need to manipulate the path string to get the format you need.

here is an expanded version of markratledge's post
tell application "Finder" to set netlink to URL of (get selection as alias)
tell application "Mail"
launch
set newMessage to make new outgoing message with properties {subject:"network link", content:netlink, visible:true}
-- Add in code for recipient, etc, etc
--send newMessage
end tell
but that still doesn't seem to work lol

Related

I need to create an applescript to get the token from an account in the Authy desktop app and concatenate it with a password

I was able to identify the names of some elements to make the click command, but I could not find the name of the element that identifies the accounts.
The idea is to click on an account, copy the token and concatenate it with a password inside the script
Commands already used:
tell application "System Events"
tell process "Authy Desktop"
set visible to true
return every UI element of front window
end tell
end tell
tell application "System Events" to return value of every attribute of window of application process "Authy Desktop"

Create mail with attachment using applescript and outlook

I've wrote a litte Applescript to make a new message with an attached file via outlook. But it didn't work and I don't know why. There is no error or something else. The message is created in the Draft-section of outlook, but the attachment is missing. Can somebody help me out?
Here's the Script:
set mailBody to "<span>TEST</span>"
set mailAdress to text returned of (display dialog "Mail Adress" default answer "" buttons {"OK"} default button 1) as string
set whichFile to file
tell application "Finder" to set whichFile to selection
repeat with aFile in whichFile
tell application "Microsoft Outlook"
set filename to name of aFile
set theNewMessage to make new outgoing message with properties {subject:"TEST " & filename, content:mailBody}
make new recipient at theNewMessage with properties {email address:{address:mailAdress}}
set theAttachmentFile to aFile as POSIX file
make new attachment at the end of theNewMessage with properties {file:theAttachmentFile}
open theNewMessage
end tell
end repeat
Greetings and thanks in advance
Speedster
Here is what I have been using as an alternative. To use the below, you need the desired message to be queued up already in your outbox. Or you can just borrow a few lines of the below and work it into your existing code.
set theAttachmentFile to "Macintosh HD:Users:Speedster:Documents:Attachment.docx" as alias
---replace this with the hard address of your selected file
tell application "Microsoft Outlook"
repeat with theMessage in the messages of the outbox
make new attachment at the end of theMessage with properties {file:theAttachmentFile}
end repeat
end tell

Apple automator & applescript : saving pictures from a web page if do not exist locally

I am currently trying to automate a task as an app but have difficulties with the step "save URLs" and need a custom applescript to replace it.
To give you the context of my project:
I bought a Toshiba FlashAir SD WIFI card for wifi tethered picture shooting.
I want to download all the file in real time from my camera with the SD WIFI card(installed in my camera) to my Mac Computer.
Toshiba FlashAir runs its own network you connect to, and you can browse the SD content through a web-browser (no ftp,no webdav..., so only http connection).
I prepared an html/Jquery page uploaded to the SD, with the FlashAir API so that when you hit the page http : // flashair you get a page with all the image links refreshed every second. It's nearly real-time and display new shot images in the browser.
I want to download those pictures on my computer so that iPhoto or any other photo app can "watch" the directory like in tethered mode and process on the fly if I need to.
On my computer side, with AUTOMATOR :
I "get the specific URL" > http : // flashair ( to reach the SD card micro server).
Then "get all the image URLs" from this specific URL and related ones
Then Download ONLY the pictures that I don't already have on my computer (this is where I lack applescript knowledge)
Then Loop for 240minutes... (to observe the remote page and download new files ONLY again and again.)
So everything work perfect but when I launch the Automation workflow, The same pictures are saved again and again with the filename suffix -01, -02, ... . It means I have the same amount of duplicate pictures as the loop instance.
The automator process "Download URLs" does not allow me to precise if I want to download only new or modified files from remote to local.
Is there someone who can help me with this "applescript" step, so that I can replace the automator "Download URLs" by a specific Applescript step that looks if the files already exists then if not download them every loop instance ?
Thanks a lot for your precious answer, I am stuck with that, and everything is flawless, but that duplicated files issue.
Damien
Here is the code you are looking for:
on run {input, parameters}
set dLocation to POSIX path of (path to downloads folder) & "test/"
set fileList to {}
set AppleScript's text item delimiters to {"/"}
repeat with i from 1 to (count of input)
# With the delimeter to '/' last item is the filename!
set urlStr to (get item i of input) as text
set urlFile to last text item of urlStr
set savedFile to (dLocation & urlFile) as POSIX file
log "Saved file is: " & savedFile
try
savedFile as alias
log "File exists: " & savedFile
on error mMsg
set end of fileList to urlStr
log "Adding URL: " & urlStr
end try
# delay 5
end repeat
return fileList
end run
All the above does is to grab the filename at the end of the link. It checks if the file exists and if not adds the link to the list of links to download. It then passes the list of links on.
After the Applescript action add a Download URLs action and you should be done.
EDIT:
So the Workflow will be like this:
Define Site URL
Action: Get URL Links from Webpages
Action: Run applescript (code above)
Action: Download URLs
Action: Pause (optional)
Action: Loop
Note that the Loop Action limits you to 1000 minutes. So you have two choices, 1) add more loop actions, or 2) launch the workflow from a script with an infinite loop...
The other way is to write the whole thing as a script and have it run continuously.
EDIT2:
Oops just reread your question. It was for 240minutes, so a single loop function will work just fine.

Getting Mac Hazel to e-mail .lnk, doc, and .xls files to my evernote account

i'm trying to automate and simplify my life. I'm new to hazel and apple scripts..
I have a lot of documents and i pull a lot of things of the web. i simply drag the link to my desktop where it makes a .lnk file.
i want to create a hazel + apple script that will look for these .lnk files and send an email with the link file attached to my evernote email address.
Any suggestions would be appreciated.
In Hazel Create a new rule.
If all ..
1, Extension - is - ink
Do the following:
2, Run AppleScript - embedded script.
Click the info icon to edit the script. Paste this script into it. With the correct email addresses, subject, content set.
set theAttachment1 to (POSIX path of theFile)
set subject_ to "subject"
set the_content to "the_content"
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:subject_, content:the_content & return & return}
tell newMessage
set visible to false
set sender to "my1#mac.com"
make new to recipient at end of to recipients with properties {address:"their#mac.com"}
make new attachment with properties {file name:theAttachment1} at after the last paragraph
(* change save to send to send*)
send --<<<<---------------- change save to send to send or send to save to save to drafts
(* change save to send to send*)
end tell
end tell
3, Add a second action to move the file to a folder. If not you may keep getting the same files sent over and over again.

Set text of a Growl Notification using Automator?

I have an Automator Application containing the action "Show Growl Notification", which is always empty when it appears. I've tried using the "Get Specified Text" and "Get Value Of Variable" actions directly before it, but nothing I've tried seems to work.
The code sample from gadgetmo is almost correct but won't work as is with Growl 1.4
An application must be registered and enabled and must provide a list of notifications it will present and also a list of which of those notifications are enabled.
You can skip all that config stuff if you just hijack the preconfigured automator settings as shown below.
Key points to note are "Automator notification" as the name of the notification and "Automator" as the source application.
tell application "System Events"
set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
end tell
if isRunning then
tell application id "com.Growl.GrowlHelperApp"
notify with name ¬
"Automator notification" title ¬
"Processing Files" description ¬
input as text application name "Automator"
end tell
end if
Use this in a Run Applescript:
tell application "System Events"
set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
end tell
if isRunning then
tell application id "com.Growl.GrowlHelperApp"
notify with name ¬
"Test Notification" title ¬
"Test Notification" description ¬
"This is a test AppleScript notification." application name "Growl AppleScript Sample"
end tell
end if
Or download it here.
You can also use this with input.
The action just passes the input through, and doesn't have any text fields that accept variables, so you will need to manually put in the message you want. The Show Growl Notification action (located inside the GrowlHelperApp bundle) does use an AppleScript, so you could modify a copy to do something like use the input if the message field is blank.

Resources