Author Topic: [SOLVED] Get name  (Read 2231 times)

0 Members and 1 Guest are viewing this topic.

Offline Rabbit

  • Newbie
  • *
  • Posts: 12
  • Karma: 0
  • Gender: Male
[SOLVED] Get name
« on: December 15, 2007, 02:02:25 PM »
I'm trying to get a script to get it's "name".

I've been able to get "Script Editor"
but not the doc "name"

this will be a read-only app on the final output. if it was a script then a

tell frontmost document
   Set a to name
end tell

Works great! but not when it's save as an App and run.

please help
Stephen Oakes
Senior Graphic Designer
Oakes Oasis

Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: Get name
« Reply #1 on: December 16, 2007, 08:56:28 PM »
Hi Rabbit and welcome the this forum,

When you run your script in Script Editor, it is running from a Script Editor document. However, when you save your script as an app it does not generate any App document.

I am curious though, are you expecting people to change the name of your script?
Michel Lemieux
Forum Administrator
-------------------------
OS X 10.6.4
Quark 6.5 / 7.5 / 8.1.6
Adobe Design Premium CS / CS2 / CS3 / CS4 / CS5
Script Debugger 4.5

Offline Rabbit

  • Newbie
  • *
  • Posts: 12
  • Karma: 0
  • Gender: Male
Re: Get name
« Reply #2 on: December 17, 2007, 11:09:16 AM »
No, people won't change the name. The main App will name a group of script with a number prefix (##### rename.app, ##### sort.app, ...).  by looking at the name, I can use the number to look up setting for the book. right now I have to rewrite scripts that call this script to pass a number to it every time I get a new book to pub.  I could use the clipboard but most times I want to keep that the way it is, (I know I could pass that info to a Var then pass it back.)

On the surface it so looks easy to get the name. Can I use System Events to do this?
Stephen Oakes
Senior Graphic Designer
Oakes Oasis

Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: Get name
« Reply #3 on: December 17, 2007, 06:57:31 PM »
Here a simple way:

Quote
001   set AppPath to (path to me) as text
002   set AppName_WithExt to my GetTextItem(AppPath, ":", -1)
003   set AppName_SansExt to my GetTextItem(AppName_WithExt, ".", 1)

004   display dialog AppName_SansExt & " (" & AppName_WithExt & ")"

005   on GetTextItem(ThisString, ThisDelim, ThisItem)
006      -- ThisString -> String to look in
007      -- ThisDelim -> Text element that delimit the string
008      -- ThisItem -> Number of the element to return
009      copy the text item delimiters to OldDelims
010      set the text item delimiters to ThisDelim
011      if class of ThisItem is list then
012         set fromItem to (item 1 of ThisItem) as integer
013         set toitem to (item 2 of ThisItem) as integer
014         set arrItem to (text items fromItem thru toitem of ThisString)
015      else
016         set arrItem to every text item of ThisString
017      end if
018      set the text item delimiters to OldDelims
   
019      if class of ThisItem is list then
020         return arrItem as text
021      else
022         if ThisItem != 0 then
023            return (item ThisItem of arrItem) as text
024         else
025            return arrItem -- return every items
026         end if
027      end if
028   end GetTextItem
Note:
The line numbers included with this script are there to aid future discussions. In order to use this script, you will have to strip all of them.
Michel Lemieux
Forum Administrator
-------------------------
OS X 10.6.4
Quark 6.5 / 7.5 / 8.1.6
Adobe Design Premium CS / CS2 / CS3 / CS4 / CS5
Script Debugger 4.5

Offline Rabbit

  • Newbie
  • *
  • Posts: 12
  • Karma: 0
  • Gender: Male
Re: Get name
« Reply #4 on: December 17, 2007, 07:48:59 PM »
on line 22 is the "!" correct? it keeps giving me an error.
Stephen Oakes
Senior Graphic Designer
Oakes Oasis

Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: Get name
« Reply #5 on: December 17, 2007, 08:14:31 PM »
Sorry, that's a Javascript convention.... It means not equal to: You should replace "!=" by Option + "="
Michel Lemieux
Forum Administrator
-------------------------
OS X 10.6.4
Quark 6.5 / 7.5 / 8.1.6
Adobe Design Premium CS / CS2 / CS3 / CS4 / CS5
Script Debugger 4.5

Offline Rabbit

  • Newbie
  • *
  • Posts: 12
  • Karma: 0
  • Gender: Male
Re: Get name
« Reply #6 on: December 18, 2007, 03:06:16 PM »
that works!

Thanks Michel
Stephen Oakes
Senior Graphic Designer
Oakes Oasis