Thursday, April 24, 2014

#1 2011-08-31 06:19:07 am

rfmusic
Member
Registered: 2011-07-30
Posts: 14

property data and (unwanted) posix path

Hi to all,
i've started using the "property" command to bring datas over the script.
I'm using a xcode droplet and i want to put the drag'n'dropped file(s) list into a property.
main problem is that it converts my file list into posix path, and i don't want it, as i have to do some modifications before.
i just want to bring data as is, why it converts it to posix path ?
here's a little script to recreate the issue:

just create a new xcode applescript droplet project
then in interface builder assign "Application" of main menu.xib to trigger "on launched"
then :

Applescript:


property allfiles : {}

on idle
end idle

on open names
   display dialog names as string
   set contents of default entry "allfiles" of user defaults to names
   set readfromproperty to contents of default entry "allfiles" of user defaults
   display dialog readfromproperty as string
end open

on launched theObject
   tell user defaults
       make new default entry at end of default entries with properties {name:"allfiles", contents:{}}
   end tell
end launched

wich is the best way to read/store values within an xcode project without the risk of being changed like this?
am i missing something ?
for string i've used a plist file till now, that works fine, but i have to convert in ascii first and then save as ascii numbers in the plist, as some characters does not works in XLS, but for things like "names" wich has multiple items inside how can i do?

sorry i'm quite new to xcode, thanks for any input

Last edited by rfmusic (2011-08-31 06:21:52 am)

Offline

 

#2 2011-09-01 07:04:31 pm

rfmusic
Member
Registered: 2011-07-30
Posts: 14

Re: property data and (unwanted) posix path

ok i realized that using property does basically the same of writing on a custom preference file using shell script and reading values using system events.

i've solved reconverting to unix path once readed, by the way i've encountered some problems cause class has not been maintained, i had to manually set it as alias to make it works as before (took a while to understand why i was getting error).

so i have a question, is there a way to change name of the plist file it does automatically when using "property" and "user default" commands ?
i've seen it creates a file called "com.apple.ASDroplet.plist" on my user folder

by the way it looks the method i was using was better cause converting to ascii i can save any kind of character without problems, while using property it looks i have some limitations, but it's much more easy to use in terms of coding.

so i don't know if is a good deal to became mad adapting the code in order to use property and user default instead of the method i was using, now i have 2 preferences files called by the application... too bad!

i've understood also how to make parameters with multiple items, just need to use {"item1","item2","etc"}, i will save many lines of coding now, but before making the changes i would like to choose the best method to store that values and keep a preference file only for preference possibly, and not for internal calculations.... i'm over 4000 lines right now, and i have already cleaned the code a lot!! :p

i'm still looking for a good alternative, probably i have to search in interface builder to see if there's an object i can use to store and read values, hope it will be easy.. smile

Last edited by rfmusic (2011-09-01 07:10:46 pm)

Offline

 

#3 2011-09-02 12:32:31 am

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10270
Website

Re: property data and (unwanted) posix path

Hi,

user defaults is the best and easiest way to manage preferences.
First define a key with a default value and register it. Then you can use it.
The default value does not overwrite any existing value

Applescript:

on registerPreferences()
   tell user defaults
       make new default entry at end of default entries with properties {name:"allfiles", contents:{}}
       -- Now we need to register the new entries in the user defaults
       register
   end tell
end registerPreferences


on readPreferences()
   tell user defaults
       set allFiles to contents of default entry "allFiles"
   end tell
end readPreferences


on savePreferences()
   tell user defaults
       set contents of default entry "allFiles" to allFiles
   end tell
end savePreferences

The best place for registering and reading is in awakeFromNiib() or applicationWillFinishingLaunching()

Last edited by StefanK (2011-09-02 12:33:08 am)


regards

Stefan

Offline

 

#4 2011-09-02 04:51:26 am

rfmusic
Member
Registered: 2011-07-30
Posts: 14

Re: property data and (unwanted) posix path

thanks for reply, any chance to set up a custom name for that plist file?
it writes on com.apple.ASDroplet.plist right now, i would like to give that the name of my app..

EDIT: Ok found, is the value of "bundle identifier" parameter inside info.plist.. perfect smile

Last edited by rfmusic (2011-09-02 04:57:52 am)

Offline

 

#5 2011-09-02 04:56:48 am

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10270
Website

Re: property data and (unwanted) posix path

Edit the key CFBundleIdentifier in Info.plist.

You can do it also in the GUI: as far as I remember Target > Get Info > Properties


regards

Stefan

Offline

 

#6 2011-09-02 05:00:34 am

rfmusic
Member
Registered: 2011-07-30
Posts: 14

Re: property data and (unwanted) posix path

ahah found the exact moment you have replied smile
thanks

Offline

 

#7 2011-09-02 11:20:18 am

rfmusic
Member
Registered: 2011-07-30
Posts: 14

Re: property data and (unwanted) posix path

i still have problems reading from a plist array

let's say i have a plist propierty like this

Applescript:


make new default entry at end of default entries with properties {name:"ThreadsName", contents:{"t1p", "t2p", "t3p", "t4p", "t5p", "t6p", "t7p", "t8p", "t9p", "t10p", "t11p", "t12p", "t13p", "t14p", "t15p", "t16p"}}

it succesfully write on the plist file as array and divide it by numbered items

now if i want to get the value of item 3 for example i write something like this:

Applescript:


display dialog (contents of item 3 of default entry "ThreadsName" of user defaults) as string

it puts all values on item 1 and leaves all the others blank, how to call a single item ?

also sometimes application does a strange hang, when i click buttons that recalls some writings or reading from/to the default plist file, application does nothing, and button keeps pressed, by the way is not hanged and if i try pressing the button again it unlocks it and does the job (twice). never happened that when i was using system events and shell script to manage parameters...

Last edited by rfmusic (2011-09-02 11:21:19 am)

Offline

 

#8 2011-09-02 11:29:05 am

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10270
Website

Re: property data and (unwanted) posix path

As described in post #3, read the array into a variable and get the item from there.

AppleScript (Studio) is single threaded, split the code into smaller handlers, then the GUI will respond quicker


regards

Stefan

Offline

 

#9 2011-09-02 04:08:06 pm

rfmusic
Member
Registered: 2011-07-30
Posts: 14

Re: property data and (unwanted) posix path

ok got it working many thanks for your time!

Offline

 

#10 2011-09-10 09:24:48 am

rfmusic
Member
Registered: 2011-07-30
Posts: 14

Re: property data and (unwanted) posix path

Hi, i'm testing the same identical code on snow leopard, it doesn't write my list of files on the plist file anymore using the same command, they have changed something maybe ?

the value is initialized like this:

Applescript:


tell user defaults
       make new default entry at end of default entries with properties {name:"DraggedFiles", contents:{}}
end tell

then on the "on open" part it's as below:

Applescript:


on open these_files
   set contents of default entry "DraggedFiles" of user defaults to these_files
end open

lookin on my plist file the entry "DraggedFiles" is empty, is as array with 0 items
what am i missing ?
on 10.5.8 it was working fine !!

i've tried other values (not array) and it writes that correctly...

also about the buttons not responding properly while the application reads or write from/to the property list file, maybe a line like this could help ?

Applescript:


call method "synchronize" of object user defaults

it's the same of writing "register" inside a "tell user defaults" ?
i have it only on the "make new default entry" part of the code, do i have to put it everytime i write on the plist file?
i've read some documents online but they are all obsolete, they talk about xcode 2.x or even 1.x

It's not a matter of cpu power, i read very small values from the plist file, i saw i still have the same problem on snow leopard and xcode 3.2.6, sometimes i click on a button and it does nothing, button stay pressed but it does nothing until i press again, then it does the job twice, there must be something else, also i'm repeating myself, but this problem has appeared since i've started using the user defaults functions, when i was using system event + shell script i've never encountered that problem, i think i have to add some other lines of codes to avoid this but i really don't know what to do honestly, any input is appreciated, thanks.

Also i've reduced the code a lot, now i'm at 1250 lines (from over 4000 + other scripts), so is not that big, i'm sure it's not a matter of cpu.

could be something about button options on interface builder maybe ? that "on release" thingy? it does it very randomly, it can go fine for one hundred times and then then give that issue twice in a row..

Last edited by rfmusic (2011-09-10 09:32:16 am)

Offline

 

#11 2011-09-10 09:36:02 am

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10270
Website

Re: property data and (unwanted) posix path

I'm wondering that files of class AppleScript alias specifier can be written to user defaults anyway!
Probably you must coerce each file to a text (in fact the path) before writing it to disk.

The difference between register and synchronize is:

register is declaring properties with default values .
As long as the value of a property is unchanged take the registered default value

synchronize is the command to write changed properties to disk right now

The problem of non-responding GUI is the single-treaded environment of AppleScript

Last edited by StefanK (2011-09-10 09:37:31 am)


regards

Stefan

Offline

 

#12 2011-09-10 09:44:25 am

rfmusic
Member
Registered: 2011-07-30
Posts: 14

Re: property data and (unwanted) posix path

sorry i'm not getting it,
you mean i have to split the "these_files" into several strings and then write that single string as items oF the "DraggedFiles" array ?
Because if i'm not remembering wrong i was not able to write a string into an array item of the plist file unless i have initialized that array with n items, and as is a drag'n'drop application i can't know how many tems i'll drop each time..

i mean if i tell to write to item 20 but my array is initialized with only 16 items i get an error, as far as i can remember

about the other problem do you think that those command may solve my issue ?
nobody has encountered that problem before ?

what you mean for single threaded, my application uses 0% cpu and it does not do other tasks, i mean, when i open the option panel the application is IDLE, it's not waiting for an input to release, in fact i can open for example the "about" window, when is hanged i cannot open it.
I had to change the code a lot to reach this, i think this is more correct than write "display panel" and then wait for a click to release..

Last edited by rfmusic (2011-09-10 09:51:12 am)

Offline

 

#13 2011-09-10 10:00:11 am

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10270
Website

Re: property data and (unwanted) posix path

you need a repeat loop to coerce the alias specifiers to string paths, something like this

Applescript:


set pathArray to {}
repeat with aFile in these_files
   set end of pathArray to (aFile as text)
end repeat

the mechanism is store an array is always either to keep the values in a variable
or read the whole array from user defaults, modify it and write it back. The size and the default value doesn't matter.

The GUI issue depends on the written code, I recommend to keep the event handlers (like onClicked) very short


regards

Stefan

Offline

 

#14 2011-09-10 01:24:24 pm

rfmusic
Member
Registered: 2011-07-30
Posts: 14

Re: property data and (unwanted) posix path

Ok i got it, basically this new version doesn't convert automatically an alias to string so we have to do it by ourselves, it worked great, also it has solved the problem of conversion to posix path (that was the main subject of this thread), it saves as unix path that is just perfect for my needs!!

you're the man!!
many thanks for your help!!

hope it works in 10.5.x now!! smile

I think i've found also the problem of my hangs, i have a "delay 1" inside the "on idle", this is causing the button not to respond properly sometimes.

i have temporary eliminated everything from the "on idle" part and it looks it works fine again!!

now i have another problem but i think it's better to write another thread as this is totally OT here.

regards

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.040 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)