I asked this in Applescript forum but thought someone might know of another way to accomplish the same end result.

I asked this in Applescript forum but thought someone might know of another way to accomplish the same end result.

Need to know to if this is even possible using a text expansion application or script or anything else.


I've been trying to figure out a way to name a file in any application in the Save dialog but I want it to follow a specific format that uses multiple list menus based on input from other list menus


I've used text expansion applications before (Keyboard Meastro, Typinator, aText, Dash, iKey, yType) for some simple task and some not so simple task but this formating might be too big of a request for those types of programs.

I would love to be wrong on that assumption, so please feel free to correct me if you know otherwise.



Desired format is:

Today'sDate_ClientCode_ProjectCode_SubProject_Part_AppUsed_Version_EditorCode



Example would look like this:

20130423_A1_BON_ShowA_Finale_LP_V1.4_AES1


This would be a simple request if everyone could remember all the codes but the list is large and at times also dependant on the previous code in the sequence.



Breakdown (in most lists, the # of list menu items may expand)


RED = User input by typing

GREEN = Auto typed with no input from user

BLUE = Auto typed after user selects item from list


Type the shortcut "?ses" to start expansion or script


Date - Should auto type today's date and follow the yyyyMMdd format, then auto type "_" then open the "Client Code" list menu

20130423_"Client list menu"


Client - Choose from a list menu of say 10 options and that choice would auto type a 2 letter code and "_" then open the "Project Code" list menu that corresponds with that "Code" (example A1)

20130423_A1_"A1 Project list menu"


Project - Choose from that corresponding list menu and auto type it's code and "_" then open the SubProject list menu that corresponds with that "Code" (example BON)


20130423_A1_BON_"BON SubProject list menu"


SubProject - Choose from corresponding list menu and auto type it's code and "_" then open the "Part" list menu (list is independent of previous choice)


20130423_A1_BON_ShowA_"Part list menu"


Part - Choose from "Part list menu" and auto type the choice and "_" then open the "Application Used" list menu (list is independent of previous choice)


20130423_A1_BON_ShowA_Finale_"Application Usedlist menu"


AppUsed - Choose from list menu and auto type two letter code and "_" then auto type the letter "V"

20130423_A1_BON_ShowA_Finale_LP_V"User Input"


Version - User input but should follow "#.#" such as 1.2 or 2.4, user hits enter when done and auto types "AES"

20130423_A1_BON_ShowA_Finale_LP_V1.4_AES"User Input"


UserCode - User inputs number and hits enter.


20130423_A1_BON_ShowA_Finale_LP_V1.4_AES1


Move cursor to the end of name


This completes the naming process but does not close the original Save menu so the user can review the new name first





Thanks in advanced.

OS X Mountain Lion (10.8.3)

Posted on Apr 24, 2013 1:23 PM

Reply
23 replies
Sort By: 

Apr 24, 2013 2:09 PM in response to Square1

I don't think you are going to have much luck with intercepting the save dialogs used in other applications, but you could possibly copy to the clipboard and/or paste into the current save dialog using the result of the naming utility. AppleScript can do this, but it would be from an Xcode/Cocoa-Applescript type of project, otherwise you are looking at whole bunch of dialogs popping up.


I've looked into developing a custom naming application like this before, but the actual (re)naming part is easy - the hard part is setting up a decent user interface.

Reply

Apr 24, 2013 2:15 PM in response to Square1

I agree with r_m: I don't think you're going to catch the save dialog, not with applescript. You might try some after-the-fact scripting, where the user saves the file with a random name and a folder action or launchd agent renames the file. I don't know how that would fit in your workflow, though.

Reply

Apr 25, 2013 3:14 PM in response to Square1

Actually, after revisiting some of my earlier prototypes, a text service might be the way to go. When a save panel opens, the default name is highlighted, so just right-clicking on it will bring up the services menu. There still isn't a way to force the use of the service, but it would only be a click away.


A regular application can be developed that provides the service, or maybe an Automator action can be created. Going the Automator action route mignt be a little bit faster to develop, but setting up a way to enter and edit the menus will take a little thought.

Reply

Apr 25, 2013 6:16 PM in response to red_menace

It's crude but as a proof of concept for the OP this automator workflow saved as a text service does pretty much what he wants:


User uploaded file


There are a few drawbacks that I see, the two main ones being


1. As it is a service there is no forcing the user to use it when they save the project.

2. In order for the service to show up there needs to be selected text in the text box but this requirement can worked into the workflow


To overcome 2 I see the user inputting the version number in the text box, selecting it and then running the service. The version number can be verified in the script and the user can be prompted to enter it again if it is wrong.


Of course 1 will always be a problem in a situation like this but unless you're coding the app from scratch there is no way to force the user to do this.


But this would still be a big improvement over not having anything to help the user come up with the correct name.


So all that really needs to be done is the coding up of the dialogs to have the user select the those bits.

Reply

Apr 25, 2013 6:33 PM in response to Frank Caggiano

It is pretty easy to whip up a GUI in an Automator action to keep away from the typical death by dialog, the tricky part is a providing a decent way to edit the menu lists. My previous project used tokens to represent the various menu and date objects, with the format determined by dragging tokens and entering text in the setup text field - a decent way to edit the menu lists was a problem with that as well.


I'll look into an Automator action with the various menu items, maybe it can be modular enough to rearrange the UI items for other formats - any ideas on some kind of management system for the menu items? Maybe property lists or text files could be used, but I found that managing the menu items was way more complicated than anything else.

Reply

Apr 26, 2013 5:11 AM in response to Square1

Thanks red_menaceand Frank Caggiano


Wow, I knew somebody smarter than me would have some idea of how to possibly make this work. I have a recording session today but will look at this over the weekend or the beginning of next week.


Since I am knew to the inner workings of the forums and you both are Level 6, correct me if I'm wrong, when I respond to the orginal post you both get updates, yes? But if I reply to one of your post what exactly happens? I assume there is a difference or why have the option?


Thanks again for the help and I hope this is something I can use and learn from. It would open up a whole world of possible things to do.

Reply

Apr 26, 2013 6:40 AM in response to Square1

Remember what I posted was just a proof of concept, there is still more work that will need to be done to this.


I think as a first round and to test out the concept you could get by with a series of choose from dialog windows that the script would put up for the user to select the different bits.


As I wrote the major drawback here is that there is no way to force the user to use this, but given the requirements of your naming scheme I think any user will be happy to use something that will make entering the name easier.



As for replying it really doesn't matter as far as seeing the posts, everyone sees everything posted here.


If you are answering or commenting on something specific in a post it is a good idea to respond to that post so your post makes senses in context. If we don;t know who you are responding to it can sometimes make understanding a post confusing.


regards

Reply

Apr 26, 2013 10:29 AM in response to Frank Caggiano

As I wrote the major drawback here is that there is no way to force the user to use this, but given the requirements of your naming scheme I think any user will be happy to use something that will make entering the name easier.


This would close the window a bit.


You could put a folder action on the folder to verify the name. If it looks "bad" you could put out a warning.


Robert

Reply

Apr 29, 2013 3:32 PM in response to Square1

Well, the good news is that I reworked my old code over the weekend (using a specific naming sequence made it a whole lot easier) and now have a functioning renamer with most of the bells and whistles intact. The application puts an accessory view in a standard open panel, but the service would look something like:

User uploaded file


The bad news is that I'm about to lose what little hair I have left trying to get it to work as a service, and an Automator action doesn't look like it will be any better. The next step is to see if I can use the service application in an Automator service (or other service wrapper) and use it from there.


If anyone else has had success with an ASObjC service, feel free to chime in - I would appreciate some clues.

Reply

May 1, 2013 10:25 AM in response to red_menace

Wow, you did all that before I could even wrap my head around the information posted last week.


Over the weekend I started messing around a little bit with Automator and AppleScripter Editor but I don't remember seeing a way to accomplish the multiple menus that you have shown above. Also, do the menus "feed" off of each other?


Because I'm under the gun a bit, I've had to move forward with what I know but I like what you have posted better. Here is what I'm doing with a $5.00 application called aText that is working "ok" so far but it's not as simple and elegant as what you are showing, which is the goal. Also, I havn't completed all the menus so I may have some unknown issues.


Below is an example of what I have so far that shows a naming squence.





Deleting of extra characters is performed by aText using cursor movement and forward delete key. This is further assisted by an option to move the cursor anywhere after an expansion occurs.


User uploaded file

User uploaded file

User uploaded file

User uploaded file

User uploaded file

User uploaded file

User uploaded file

User uploaded file

User uploaded file

User uploaded file

Reply

May 1, 2013 10:51 AM in response to Square1

Xcode is needed for what I posted - I just tweaked a project I started a few years ago, so the basics were already built (there isn't really that much code). The menus are populated with the contents of a .plist file (which can be edited with a text editor), so once the clients, projects, etc, are set up it is just a matter of clicking on the desired menu item - I figured that was the approach you were going for to prevent errors such as typos.


ComboBoxes are used for the menus, which have a text field in addition to the menu, so if the desired menu item isn't there it can be typed in. Addiitons made that way will be added to the list for the next time via the application preferences. The final file name is built as the items are selected, and the rename will not continue until all items are selected (I threw an optional text field in there that doesn't need to be filled in).


The renamer is a working application right now, I'm just having a problem getting it to work as a service. The application puts up a file selection panel where you can select a single file to be renamed (the original application was for renaming scanned documents), so if you would like to take a look at that send me an email (my address is in my profile).

Reply

May 1, 2013 11:23 AM in response to Square1

This AppleScript will put up choose from list dialogs to get the user input. It isn;t as clean as what red_menace was working on but this will work as a service.


Right now the user input part is missing and there are no real error checks but it will give you an idea of what can be done



property clientCodeList : {"A1", "A2", "A3"}

property projectCodeList : {"BON", "BOB", "CAT", "DOG"}

property subProjectCodeList : {"showA", "showB", "showC"}

property partCodeList : {"Finale", "Start", "WhatsUp"}

property appUsedCodeList : {"LP", "CD", "QQ", "PP"}



set finalStr to datePart() & "_" & clientCode() & "_" & projectCode() & "_" & subProjectCode() & "_" & partCode() & "_" & appUsedCode() & "_V" & "userInput" & "_AES" & "userInput"


display dialog finalStr


on datePart()


set now to current date

if (day of now < 10) then

set dayStr to "0" & day of now

else

set dayStr to (day of now) as text

end if


if (month of now as integer < 10) then

set monthStr to "0" & (month of now as integer)

else

set monthStr to (month of now as integer) as text

end if


set dateStr to ((year of now) as text) & monthStr & dayStr


return dateStr

end datePart


on clientCode()



choose from listclientCodeListwith title "Client Codes"

if the result is not false then

return item 1 of result

else

return "NIL"

end if


end clientCode


on projectCode()


choose from listprojectCodeListwith title "Client Codes"

if the result is not false then

return item 1 of result

else

return "NIL"

end if

end projectCode


on subProjectCode()


choose from listsubProjectCodeListwith title "Client Codes"

if the result is not false then

return item 1 of result

else

return "NIL"

end if

end subProjectCode


on partCode()


choose from listpartCodeListwith title "Client Codes"

if the result is not false then

return item 1 of result

else

return "NIL"

end if

end partCode


on appUsedCode()


choose from listappUsedCodeListwith title "Client Codes"

if the result is not false then

return item 1 of result

else

return "NIL"

end if

end appUsedCode


Reply

May 1, 2013 2:10 PM in response to red_menace

Well, I think I found out why the services weren't working - AppleScriptObjC uses some hacks magic in order to call Cocoa methods using a variation on the AppleScript handler naming convention, but the Services API looks for a method with an Objective-C signature. I'm not sure if something changed in Mountain Lion, since I've seen service examples for both ASObjC and MacRuby, but I wasn't able to get them to work due to the method not being found. Setting up an Objective-C skeleton did work, so it looks like a service is doable, although I have some code rearranging to do.

Reply

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

I asked this in Applescript forum but thought someone might know of another way to accomplish the same end result.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.