Transmit 4 AppleScript - Close new Document when script completes - ftp

I've been experimenting a bit with CodeKit and I wanted to insure that my changes were auto-uploading to my web server.
To solve this, I have written an AppleScript recently that waits until files are processed and then runs on the entire project directory.
The problem I'm having is that my script keeps opening up new "windows". Ideally, I'd like to never have more than a single window open at one time, so I thought I could have the script close the new document that's created. However, I'm struggling with the syntax.
Here is my code:
tell application "Transmit"
set myFave to item 1 of (favorites whose name is "Favorite Name")
set myRules to (skip rules whose enabled is true)
tell current tab of (make new document at end)
connect to myFave
change location of local browser to path ""
change location of remote browser to path ""
synchronize local browser to remote browser using skip rules myRules
close remote browser
end tell
end tell
So my question(s) are:
Is there a better/more efficient way to do what I'm trying to do?
If I'm on track, how can I set that new document being created to close once the script is done running?

I ended up answering my own question!
The answer was surprisingly simple. I noticed in the AppleScript dictionary for Transmit that there was a "close" method which relates to documents (which was the thing I was trying to close).
I was puzzled at first because I thought I'd need to specify what I was closing. But ultimately, I just added "close" after "close remote browser".
tell application "Transmit"
set myFave to item 1 of (favorites whose name is "TitanHost")
set myRules to (skip rules whose enabled is true)
tell current tab of (make new document at end)
connect to myFave
change location of local browser to path ""
change location of remote browser to path ""
synchronize local browser to remote browser using skip rules myRules
close remote browser
close
end tell
end tell
I hope this helps someone else!

Related

AppleScript executes both If and Else, but only on a network user, not on a local admin

I'm trying to modify a local property file for an application, for each of our Network users, who each have local User folders on each client computer. The property file is stored in the local user folder, that I want to do the following with, so this happens on login rather than having to do this manually on a whole lot of users:
Check if it has the relevant modifier string already
If it does not, append the string to the text configuration file
The following code works perfectly when executed from the admin account: It adds the string if it isn't already there, and if it is, then it displays the Dialog window (That I just have there to debug it)
However, the moment I log on with a Local Network Account, it BOTH displays the Dialog Window AND adds appends the string to the configuration file, and keeps adding a new one for every login. It applies these to the correct file, so the file path is still pointing at the right config file.
I don't understand why the same script would behave like this?
set userName to short user name of (system info)
set JournalProps to "/Users/" & userName & "/NameOfTheConfigFileHere"
close access (open for access JournalProps)
set FontSize to "name_fontsize=18"
set TheFileContents to paragraphs of (read JournalProps)
if FontSize is in TheFileContents then
set DisplayText to "Fontsize already set"
display dialog DisplayText
else
write linefeed & "name_fontsize=18" & linefeed to JournalProps as "utf8" starting at eof
end if

Mac Automator/Applescript(?) to extract URL's from Mail messages

I'm trying to get a text document list of any links in a bunch of email messages that reside in the latest Mac Mail.app (OS X 10.10.2 Yosemite), and am simply stumped.
I thought I'd be able to just...
Put a couple of Automator.app actions together in a Service/Workflow,
Select/highlight all the email messages within the Mail.app,
Select that Service or run that Workflow,
And have a text document with every URL/link that could be found within them all.
However, this didn't work.
I figured out how to do this with one email message at a time, but that's not what I want. attached is a screenshot of 3 workflows. The first one is the one that works with just one email message & highlighting all the text in it & running the Service. the other two just simply don't work.
I also notice that the the first shows up in the Service Menu with a single email open; once I highlight more than one email message, the option goes away from the Service menu.
Any tips or tricks?
I figured out how you could reach your goal, start with creating a new service within Automator (input: "No input", application: "Mail")
The first action is Get Selected Mail Messages (Get selected: messages)
The second action is Execute AppleScript with the following script:
on run {input, parameters}
set mailContentList to {}
tell application "Mail"
repeat with selectedMail in input
set end of mailContentList to content of selectedMail
end repeat
end tell
return mailContentList
end run
This script simply walks through the given messages, reads out the content and passes this list to the next action
The third action is Extract URLs from Text. This is listed as "Extract Data from Text" and one of the types of data is "URLs".
And the final action is New TextEdit Document
Save it with a nice name like Extract URLs from selected mails
After that the Service is available inside the Services menu inside the Mail app.
In my test I found a few internal URLs without http:// from links to anchors, so maybe you want to delete all URLs that do not start with http. You can do so by using another action before creating the new TextEdit document:
Filter Paragraphs with options "Paragraphs that start with http" (don't know how these parameters are called in English Automator, sorry)
Feel good, Michael / Hamburg

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.

QTP: Unique browser identificator not related to title?

In my QTP keywrord driven automation, I would like to open browser and then automatically call all functions on that browser. I noticed it does work even when the browser title changes but I am not sure whether its coincidence or not.
I would need to open browser with e.g. ID and then simply call Browser("MyID"). functions. Is there any way or I can rely on QTP even when the browser changes its name?
QTP doesn't use the title to identify the browser, the description usually is based on when the browser was created (see the Creation Time ordinal identifier). So if the state of your machine is the same (no other browsers were open before beginning to test) then the identification should be consistent.
During your testing, if there's only one Browser window open all the time , then
Just adding a "Browser" object in your OR , without any identification property would work.
If there are multiple browsers open, then you might have to add one or more of
Name
Title
Creation time.
Avoid using Creation time though.

Get network address of a file in 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

Resources