Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old May 24, 2009, 10:52 PM   #1
open0source
macrumors newbie
 
Join Date: Oct 2008
Applescript in Automator - how to accept input?

I'm a gigantic newbie to Applescript and am trying to write (what I think would be) a pretty simple script for a workflow. Basicly, the standard "Set Spotlight Comments For Finder Items" function, but I want the comments that are already on the file to show up in the entry box. What it's supposed to look like here:

http://i271.photobucket.com/albums/j...Picture2-2.png

But with the actual filename replaced by a variable of the path of the file that is being opened/dropped-onto the workflow. Any guidance is greatly appreciated.


(Edit)

This seems to work for getting the comments from a dropped file into a dialog box:

on open droppedItem
set itemPath to POSIX path of droppedItem
set itemComments to do shell script "mdls -name kMDItemFinderComment " & itemPath
display dialog itemComments
end open

but I can't use it as the workflow's script (replacing "display dialog" with "return")

(Edit 2)

Ditched automator, got a bare-bones-version working

on open droppedItems
try
set checkForMultipleItems to second item of droppedItems
on error
--Do nothing
end try
set theFile to first item of droppedItems
tell application "Finder"
set currentComments to (get comment of theFile)
set title to "Spotlight Comments:"
set r to display dialog title default answer currentComments
end tell
end open

(Sorry for wasting anyone's time)

I'll update one more time when the entire thing is done, in case someone would like the final script.

(Edit 3)
Done,

on open droppedItems
try
set checkForMultipleItems to second item of droppedItems
on error
--Do nothing
end try
set theFile to first item of droppedItems
tell application "Finder"
set currentComments to (get comment of theFile)
set title to "Spotlight Comments:"
set r to display dialog title default answer currentComments buttons {"Cancel", "Write"} default button 2
set newComments to text returned of r
if button returned of r is "Write" then
set comment of theFile to newComments
else
set comment of theFile to currentComments
end if
end tell
end open

Last edited by open0source; May 25, 2009 at 10:31 PM.
open0source is offline   0 Reply With Quote
Old May 27, 2009, 10:27 PM   #2
mysterytramp
macrumors 65816
 
mysterytramp's Avatar
 
Join Date: Jul 2008
Location: Maryland
Newbie? Nice work.

Just one question: Why do you have the try ... on error ... block? I left it out here, and offered a way to do multiple files with one drop.

Code:
on open droppedItems
    set numItems to the count of droppedItems
    -- this will handle multiple items
    tell application "Finder"
        repeat with x from 1 to numItems
            set theFile to item x of droppedItems
            set theName to the name of theFile -- this will help user know which file s/he's commenting
            set currentComments to (get comment of theFile)
            set title to "Spotlight Comments of " & quote & theName & quote
            set r to display dialog title default answer currentComments buttons {"Cancel", "Write"} default button 2
            set newComments to text returned of r
            if button returned of r is "Write" then
                set comment of theFile to newComments
            else
                set comment of theFile to currentComments
            end if
        end repeat
    end tell
end open
There's one "bug." The user might think "Cancel" will skip a file, when here it exits the script. Might make sense to have a three button dialog: Cancel, Skip & Write.

Nice bit of work for a noob.

mt
__________________
What looks large from a distance, close up ain't never that big.
mysterytramp is offline   0 Reply With Quote
Old Dec 4, 2010, 04:56 PM   #3
axelmie
macrumors newbie
 
Join Date: Dec 2010
Hi, I am new here.
How can I change following script to work by double clicking instead of dropping files onto it?

Code:
on open droppedItems
    set numItems to the count of droppedItems
    -- this will handle multiple items
    tell application "Finder"
        repeat with x from 1 to numItems
            set theFile to item x of droppedItems
            set theName to the name of theFile -- this will help user know which file s/he's commenting
            set currentComments to (get comment of theFile)
            set title to "Spotlight Comments of " & quote & theName & quote
            set r to display dialog title default answer currentComments buttons {"Cancel", "Write"} default button 2
            set newComments to text returned of r
            if button returned of r is "Write" then
                set comment of theFile to newComments
            else
                set comment of theFile to currentComments
            end if
        end repeat
    end tell
end open
thank you
axelmie is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Can't stop an Applescript with Automator Niouky Mac Programming 18 Apr 20, 2014 03:46 AM
Automator and/or AppleScript Help jbsmithmac Mac Programming 6 May 5, 2013 05:02 PM
Automator and/or Applescript Help downingp Mac Programming 2 Oct 24, 2012 08:35 PM
Applescript and Automator Mix anton1s Mac Programming 0 Oct 20, 2012 08:02 PM
Applescript application not working within Automator Jeshua Mac Programming 0 Aug 3, 2012 07:41 PM

Forum Jump

All times are GMT -5. The time now is 08:43 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC