Having trouble with remote folder actions with AppleScript - applescript

So I have an Applescript to help with naming photo's appropriately for data entry to assign it to a Unique ID. Since we're using Mac's this is done in AppleScript. This works great but it's only for one machine. What is now needed is to work on multiple machines. What I want to do is put the photos on our server and have the client machines do the action on the folder from there.
The problem I am currently having is that the script does not authenticate the user and does not run the script even though the info is correct. Am I doing this correctly?
tell application "Finder" of machine "eppc://user:password#server.local"
set renameFiles to the selection
set inventoryFiles to every file in folder (((path to documents folder) as text) & "Inventory Photos")
set currentIndex to the count of inventoryFiles
repeat with i from 1 to the count of renameFiles
set currentFile to (item i of renameFiles)
set new_name to ((10000 + currentIndex + i) as text) & ".jpg"
set name of currentFile to "a" & new_name
end repeat
end tell
Thank you for any help

Related

Applescript to extract subject line

Total n00b here, definitely not a programmer. Would love some assistance with an applescript. I'm basically trying to extract a subject line from emails in a particular folder underneath my inbox. I need it to yank out the subject line, look for some numbers (ex. 123456) and pull out the last 4 digits. Then put that into a text file. Below is what I have so far, but it's not working. I'm not getting any output at all. Any guidance would be greatly appreciated!
tell application "Microsoft Outlook"
set theAccount to exchange account “my account"
set topFolder to folder "Inbox"
set subFolder to folder “Stuff"
set theMessages to messages of subFolder
set folderPath to ((path to home folder from user domain as string) & “emails")
repeat with aMessage in theMessages
my SetSubject(subject of aMessage)
end repeat
end tell
on SetSubject(theSubject)
tell application "Microsoft Outlook"
try
save theSubject in ((path to home folder from user domain as string) & “emails" & “numbers.txt" as string)
end try
end tell
end SetSubject
end
I don't know what your criteria are to filter the subjects.
This is an example to write the last 4 characters of all subjects of the messages in the specified mailbox into a file numbers.txt in folder emails in the home folder, one subject per line.
If an error occurs – for example the number of characters in the subject is less than 4 – the file is closed reliably and the script aborts.
set numbersFile to (path to home folder as text) & "emails:numbers.txt"
tell application "Microsoft Outlook"
set theSubjects to subject of messages of folder "Stuff" of folder "Inbox" of exchange account "my account"
end tell
try
set fileDescriptor to open for access file numbersFile with write permission
repeat with aSubject in theSubjects
write (text -4 thru -1 of aSubject & return) to fileDescriptor starting at eof
end repeat
close access fileDescriptor
on error
try
close access file numbersFile
end try
end try

How can i create a new iCal event from file names in a folder?

Usually i quickly update my TODO list creating a new empty file named like this:
2013-10-01 Tell a friend that stackoverflow rocks
2013-10-23 Prepare my super meeting about coding
and so on..
i just need a workflow or applescript that take all file in the folder, extract the date and the title from the file name and creates a new iCal event on that day with that title!
it seems so easy, but how can i achieve that?
Here's something in straight Applescript.
Note: It depends on you changing your date format to DD-MM-YYYY (due to Applescripts in built date parser)
tell application "Finder"
set data_folder to folder POSIX file "/Users/me/Desktop/my_ical_data"
set all_items to every item of data_folder
end tell
set my text item delimiters to {" "}
repeat with cur_item in all_items
set nm to the name of cur_item
set event_date to date (text item 1 of nm)
set event_desc to (text items 2 thru -1 of nm) as string
tell application "iCal"
tell calendar "Work" -- name of calendar you wish to add to
make new event with properties {summary:event_desc, start date:event_date, description:""}
end tell
end tell
end repeat
This does not require you to change the date format in System Preferences:
tell application "Finder" to name of items of folder POSIX file "/Users/username/todo"
repeat with l in result
set s to text ((offset of space in l) + 1) thru -1 of l
set d to current date
tell d to set {year, month, date, time} to {text 1 thru 4 of s, text 6 thru 7 of s, text 9 thru 10 of s, 0}
tell application "iCal" to tell calendar "Work"
make new event with properties {summary:s, start date:d}
end tell
end repeat

Check for part of a folder name in applescript

I have an applescript that checks for one of several external HDs I connect to my computer and makes an index of their contents. All the HDs follow the naming scheme HK_12345 where the first two letters are always the same but the numbers are different for each drive. I want the script to only check for drives with the 'HK' designation regardless of the ending numbers. I have this but it is not working. Any advice?
set folderContains to "HK_"
tell application "Finder"
set triggerFolder to folder whose name contains folderContains
end tell
tell application "Finder"
if folder triggerFolder exists then
-- some other code
end if
end tell
You should check for disks not folders:
set diskContains to "HK_"
tell application "Finder"
set selectedDisks to disks whose name contains diskContains
-- some other code
end tell

How to Specify filepath but not name InDesign applescript

I am new to applescript.
I am trying to create an Automator script app that opens a batch existing files in InDesign, finds and changes text within the file. ( I thought this would be the complicated bit but it's not it was easy)
What I'm struggling with is then saving these files in another location but using the original filenames as I need to keep the original files.
I have a script to specify a path and a filename but I need to specify the path only and use the existing filename. Is this possible?
The code I tried was this:
tell application "Adobe InDesign CS5.5"
save document 1 to "users:xxx:Desktop:"
close document 1
end tell
It doesn't seem to work for the reason that I'm not specifying a filename BUT I DON'T WANT TO! Is there a way of calling up the original filename?
I'm assuming there must be a way of doing this, as I can't see the point of a script that is specific to one particular file.
My next step is to then rename the files by replacing the last bit of the filename eg:
xxx_xxx_M6.indd to xxx_xxx_M7.indd
I know how to do this in another script but if it can be done in the above section that would be great.
If you want to use the original file name when saving, you can just pull it from the file's properties and combine it with the path you want to save to, like so:
set origName to the name of document 1 as string
save document 1 to ("your:path:here:" & origName)
EDIT: If you already have your own routine for replacing the suffix, you can just perform those operations on origName before you pass it to the save command. I'll leave my look at suffix replacement below just in case it's helpful to anyone.
As for the second part of your question, about replacing a suffix, it depends on what exactly you want to do. From your example I’m guessing you want to increment a number, which you could do with the following code:
set thePoint to the offset of "." in origName
set firstPart to (characters 1 through (thePoint - 1) of origName) as string
set fpLength to the length of firstPart
set newSuffix to ((the last character of firstPart) as number) + 1
set newName to (characters 1 through (fpLength - 1) of firstPart) & newSuffix ¬
& ".indd" as string
This takes separates the file’s name from its extension, creates a new suffix by incrementing the last character (coerced to a number) of that name by 1, and then combines the lot to form a full file name that you can then use in the save command.
The key is breaking apart the original file name, then performing operations on the parts.
Now, this currently has a few limitations: any suffix other than a single digit makes things more complicated (though not impossible), and assumes that anyone running the script has “Show all filename extensions” enabled in the Finder’s preferences (this can be worked around, though).
Wrapping everything up gives us this:
tell application "Adobe InDesign CS5.5"
set origName to the name of document 1 as string
set thePoint to the offset of "." in origName
set firstPart to (characters 1 through (thePoint - 1) of origName) as string
set fpLength to the length of firstPart
set newSuffix to ((the last character of firstPart) as number) + 1
set newName to (characters 1 through (fpLength - 1) of firstPart) ¬
& newSuffix & ".indd" as string
save document 1 to ("your:path:here:" & newName)
end tell
If you could provide some more information about the suffixes you’d intend to use I’d be happy to update my answer.
InDesign documents have 3 properties that could interests you:
name : "xxx_xxx_M6.indd"
file path : file "Macintosh HD:sourceFolder:"
full name : file "Macintosh HD:sourceFolder:xxx_xxx_M6.indd"
So, to save (& close) the open file on the desktop, with same name, you could do this :
tell application "Adobe InDesign CS5.5"
save document 1 to "users:xxx:Desktop:" & name of document 1
close document 1
end tell

Check if an application exists using AppleScript

This code does not work for apps that do not exist because it prompts the user to look for "FooApp" (and I don't want to interact with the user):
get exists application "FooApp"
This code only works for apps whose process name matches its application name, which covers most but not all applications:
tell application "System Events"
get exists application process "FooApp"
end tell
(For example on my machine "OmniGraffle Professional" is a process name but the corresponding application name is "OmniGraffle Professional 4".)
#regulus6633 is right to point out you’re doing two separate things in your examples, and also his advice about bundle identifiers is spot on.
My preferred way to check if an application is installed is the following:
try
tell application "Finder" to get application file id "bundle.id.here"
set appExists to true
on error
set appExists to false
end try
This avoids the “Where is application x?” dialog and assigns a boolean value to appExists. You could also display alert in the on error block (or anything you desire).
For your second example, you could write:
tell application "System Events"
set processIsRunning to ((bundle identifier of processes) ¬
contains "com.bundle.id.here")
end tell
It does almost exactly what #regulus6633’s code does, but grabs the list of processes and checks it in a single line. You also don’t have to worry about initialising processIsRunning.
If you're using application names just swap bundle identifier for name.
Notice that your 2 scripts do different things. The first one checks if it is on the computer. The second one checks if it is currently running. So here's how to do the first thing.
set doesExist to false
try
do shell script "osascript -e 'exists application \"foo\"'"
set doesExist to true
end try
return doesExist
And note that as you point out some applications have a variety of names. In those cases you can use the bundle id of the app instead of it's name. Here's how to get the id of Safari and use it...
set appID to id of application "Safari"
exists application id appID
And if you wanted to see if it is running, like in your second script, you could do this...
set processIsRunning to true
tell application "System Events"
set runningProcesses to processes whose bundle identifier is appID
end tell
if runningProcesses is {} then set processIsRunning to false
return processIsRunning
This is an old question but the answer may still be helpful. The following shell script doesn't launch the application, avoids the "Where is application x?" dialog if the application doesn't exist, accepts either the application name or bundle id as input, and returns the application's bundle id if it exists or an empty string if it doesn't:
set appBundleId to do shell script "osascript -e " & ("id of application \"" & appRef & "\"")'s quoted form & " || osascript -e " & ("id of application id \"" & appRef & "\"")'s quoted form & " || :"
set doesExist to (appBundleId ≠ "")
where appRef is either the application name or bundle id.
Another way of doing this, should you have two applications with the same bundle identifier, is to use the application names. For instance, Adobe InDesign CS5.5 and Adobe InDesign CS6 both have com.adobe.InDesign as their bundle identifier.
tell application "System Events"
name of every process contains ("Adobe Photoshop CS5.5")
end tell

Resources